Created
April 19, 2020 01:44
-
-
Save schrmh/989fe3a5316ba7b50b864f7acf978ce4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Compile with: gcc -o test XSendEvent3.c -lX11 | |
//https://tronche.com/gui/x/xlib/events/structures.html | |
//https://tronche.com/gui/x/xlib/events/keyboard-pointer/keyboard-pointer.html#XButtonEvent | |
//https://www.x.org/releases/X11R7.5/doc/man/man3/XKeyEvent.3.html | |
#include <X11/Xlib.h> | |
// Simulate mouse click | |
void click (Display *display, int button) | |
{ | |
// Create and setting up the event | |
XEvent event; | |
event.xbutton.button = button; | |
event.xbutton.subwindow = DefaultRootWindow (display); | |
while (event.xbutton.subwindow) | |
{ | |
event.xbutton.window = event.xbutton.subwindow; | |
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); | |
} | |
// Press | |
event.type = ButtonPress; | |
XSendEvent (display, PointerWindow, True, ButtonPressMask, &event); | |
// Release | |
event.type = ButtonRelease; | |
XSendEvent (display, PointerWindow, True, ButtonReleaseMask, &event); | |
} | |
int main (int argc, char *argv[]) | |
{ | |
Display *display = XOpenDisplay(0); | |
click (display, Button1); | |
XCloseDisplay(display); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment