Sending X11 click event doesn't work with some windows

心不动则不痛 提交于 2019-12-05 10:32:46

Thanks to ninjalj's comment above for putting me on the right track. I don't like the idea of relying on an extension to do this and the extra dependency it creates, but it is a pretty standard extension too. Works perfect...

For those running into the same issue as me, the following code block replaces the code I was using before and works well:

#include <X11/extensions/XTest.h>

void SendClick(int button, Bool down) {
    Display *display = XOpenDisplay(NULL);
    XTestFakeButtonEvent(display, button, down, CurrentTime);
    XFlush(display);
    XCloseDisplay(display);
}

Much shorter!

For Ubuntu, don't forget to install the libxtst-dev package. Be sure to add -lXtst to your LDFLAGS.

This link is also useful:

X11 Fake Mouse Events Generation using XTest Extension http://bharathisubramanian.wordpress.com/2010/04/01/x11-fake-mouse-events-generation-using-xtest/

Here is a link explaining how to use the XTest Extension for the generation of fake keyboard events:

X11 Fake Key Event Generation using XTest Extension http://bharathisubramanian.wordpress.com/2010/03/14/x11-fake-key-event-generation-using-xtest-ext/

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!