How do we simulate a mouse click with Xlib / C?

…衆ロ難τιáo~ 提交于 2019-12-05 04:14:32

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.

xdotool is the easy way of doing this. It's a command line tool. You can use it in simple scripts. For example:

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