Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <fcntl.h>
- #include <errno.h>
- #include <termios.h>
- #include <unistd.h>
- #include <xdo.h>
- #include <X11/Xlib.h>
- #include <X11/keysym.h>
- int open_serial(char *port);
- void close_serial(int fd);
- int main()
- {
- sleep(1); //wait 1 second
- printf("creating xdo...\n");
- xdo_t* myXdo = xdo_new(NULL);
- printf("xdo created...\n");
- printf("getting display...\n");
- // Obtain the X11 display.
- Display *display = XOpenDisplay(0);
- if(display == NULL)
- {
- printf("could not open display, exiting...\n");
- return -1;
- }
- printf("getting root window...\n");
- // Window focus
- int revert;
- Window winFocus;
- int fd = open_serial("/dev/ttyACM0");
- if(fd == 0)
- {
- printf("serial error, exiting...\n");
- return -1;
- }
- char buff;
- unsigned int rd;
- while(1)
- {
- XGetInputFocus(display, &winFocus, &revert); //la ventana que tiene el focus
- rd = read(fd, &buff, 1);
- switch(fd)
- {
- case 1:
- xdo_keysequence_up(myXdo, winFocus, "A", 12000);
- xdo_keysequence_down(myXdo, winFocus, "A", 12000);
- break;
- case 2:
- xdo_keysequence_up(myXdo, winFocus, "B", 12000);
- xdo_keysequence_down(myXdo, winFocus, "B", 12000);
- break;
- case 3:
- xdo_keysequence_up(myXdo, winFocus, "C", 12000);
- xdo_keysequence_down(myXdo, winFocus, "C", 12000);
- break;
- default:
- break;
- }
- }
- printf("exiting...\n");
- XCloseDisplay(display);
- xdo_free(myXdo);
- close_serial(fd);
- return 0;
- }
- int open_serial(char *port)
- {
- int fd = open(port, O_RDWR | O_NOCTTY | O_NDELAY);
- if(fd == -1)
- {
- printf("Could not open %s\n", port);
- return 0;
- }
- fcntl(fd, F_SETFL, 0);
- printf("Port %s has been sucessfully opened and %d is the file description\n", port, fd);
- return fd;
- }
- void close_serial(int fd)
- {
- close(fd);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement