| 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <string.h> |
| 4 | |
| 5 | #include <unistd.h> |
| 6 | |
| 7 | #include <X11/Xlib.h> |
| 8 | #include <X11/Xutil.h> |
| 9 | |
| 10 | /* move mouse |
| 11 | #include "Xlib.h" |
| 12 | |
| 13 | int delta_x = 500, delta_y = 160; |
| 14 | Display *display = XOpenDisplay(0); |
| 15 | Window root = DefaultRootWindow(display); |
| 16 | XWarpPointer(display, None, root, 0, 0, 0, 0, delta_x, delta_y); |
| 17 | XCloseDisplay(display); |
| 18 | return 0; |
| 19 | */ |
| 20 | |
| 21 | void mouseClick(int button) |
| 22 | { |
| 23 | Display *display = XOpenDisplay(NULL); |
| 24 | |
| 25 | XEvent event; |
| 26 | if(display == NULL) |
| 27 | { |
| 28 | fprintf(stderr, "Cannot open display!!!\n"); |
| 29 | exit(EXIT_FAILURE); |
| 30 | } |
| 31 | |
| 32 | memset(&event, 0x00, sizeof(event)); |
| 33 | |
| 34 | event.type = ButtonPress; |
| 35 | event.xbutton.button = button; |
| 36 | event.xbutton.same_screen = True; |
| 37 | |
| 38 | XQueryPointer(display, RootWindow(display, DefaultScreen(display)), &event.xbutton.root, &event.xbutton.window, &event.xbutton.x_root, &event.xbutton.y_root, &event.xbutton.x, &event.xbutton.y, &event.xbutton.state); |
| 39 | |
| 40 | event.xbutton.subwindow = event.xbutton.window; |
| 41 | |
| 42 | while(event.xbutton.subwindow) |
| 43 | { |
| 44 | event.xbutton.window = event.xbutton.subwindow; |
| 45 | |
| 46 | XQueryPointer(display, event.xbutton.window, &event.xbutton.root, &event.xbutton.subwindow, &event.xbutton.x_root, &event.xbutton.y_root, &event.xbutton.x, &event.xbutton.y, &event.xbutton.state); |
| 47 | } |
| 48 | |
| 49 | if(XSendEvent(display, PointerWindow, True, 0xfff, &event) == 0) fprintf(stderr, "Errore nell'invio dell'evento !!!\n"); |
| 50 | |
| 51 | XFlush(display); |
| 52 | |
| 53 | usleep(100000); |
| 54 | |
| 55 | event.type = ButtonRelease; |
| 56 | event.xbutton.state = 0x100; |
| 57 | |
| 58 | if(XSendEvent(display, PointerWindow, True, 0xfff, &event) == 0) fprintf(stderr, "Errore nell'invio dell'evento !!!\n"); |
| 59 | |
| 60 | XFlush(display); |
| 61 | |
| 62 | XCloseDisplay(display); |
| 63 | } |
| 64 | |
| 65 | int main() { |
| 66 | mouseClick(1); |
| 67 | } |