c++ - 如何使用 Xlib 模拟拖动 Action ?

标签 c++ linux qt x11 xlib

我有一个使用 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/

相关文章:

linux - 在 Perl 中是否有等同于 `tail -f` 的东西?

android - 暂时以编程方式禁用 Qt 中的屏幕旋转

c++ - 根据宽度缩放 QWidget 高度

c++ - 开发跨平台 C++11 代码

c++ - 对命名空间范围感到困惑!

linux - 从 Perl 在 (Ubuntu) Linux 上启动一个独立的 Selenium RC 服务器

c++ - Qt:检查文件夹中的文件是否已更改

c++ - DLL 中使用的全局变量

c++ - 为什么我的函数打印 '0' ?

linux - 从 CLI 和浏览器运行 PHP 代码给出不同的结果