I want to find C / Xorg code to 'enter' a left mouse button click. I'd expect a single line of code but the only things I've found written in C are about two dozen lines long and they don't work anyway :( It seems it can be done in Windows, but I'm in Linux.
The reason for the question is that I've written a utility that lets me move my mouse pointer between several screens using the keyboard. The only problem is that if I move to a location where window abc used to be but another window xyz has been loaded on top of that same location, the mouse pointer moves to xyz just fine, but xyz doesn't have focus -- until I left click the mouse. So, I want to build the 'click' into my code.
The code I tried that didn't work was based on XSendEvent().
Yes, I've more or less come to understand. Anyway it seems this is the way:
{
#include <X11/extensions/XTest.h>
XTestFakeButtonEvent(display, 1, True, CurrentTime);
XTestFakeButtonEvent(display, 1, False, CurrentTime);
XFlush(display);
}
... and add " -lXtst " to the LDFLAGS line in the Makefile.
Xlib seems to be so bloody difficult. I've had advice to use other libraries, I wish I knew how to go about changing over.
Thanks R.
Why not just directly raise/focus the window rather than trying to make a fake click event? That should be a lot more reliable and work with all window managers, even non-click-to-focus ones.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With