我有一个使用 Xlib 库在屏幕上模拟鼠标的应用程序。
我使用了 XQueryPointer 和 XWarpPointer 函数,通过它们我可以模拟鼠标移动和单击。我的问题是我无法“拖动”元素(它是一个带有一些 block 的界面,您可以在用 C++ 编写并在 Ubuntu 上启动的 Qt 应用程序中移动它们)。
我使用了此摘录的许多部分:
Sending X11 click event doesn't work with some windows
这个功能可以帮助我吗?
::XGrabPointer(mDisplay, window, True,
ButtonPressMask |
ButtonReleaseMask |
PointerMotionMask |
FocusChangeMask |
EnterWindowMask |
LeaveWindowMask,
GrabModeAsync,
GrabModeAsync,
RootWindow(mDisplay, DefaultScreen(mDisplay)),
None,
CurrentTime);
你有什么想法吗?
提前谢谢您。
最佳答案
如果您同意生成子进程,则可以轻松使用 xdotool
来实现此目的,如下所示:
xdotool mousedown 1
sleep 0.5
xdotool mousemove_relative --sync 200 200
sleep 0.5
xdotool mouseup 1
http://www.semicomplete.com/projects/xdotool/
http://tuxradar.com/content/xdotool-script-your-mouse
source code to xdotool
如果您想使用 XTest
库在 C 语言中自行完成此操作,那么这将是一个很好的起点。
关于c++ - 如何使用 Xlib 模拟拖动 Action ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14218740/