多屏系统中C中鼠标光标位置

发布于 2024-10-06 13:34:22 字数 489 浏览 0 评论 0原文

在多屏Linux下,如何在C语言的X窗口中设置鼠标光标?我有 2 个显示器(具有不同的分辨率)插入到一台 Linux 电脑上。 我使用“:0.1”来寻址第二个监视器。我从显示器 1 运行应用程序,同时将鼠标保持在显示器 1 上......结果鼠标移动但不会跳到显示器 2 上。 如果我手动将鼠标光标放在显示器 2 上并从显示器 1 运行应用程序,鼠标就会移动。

我需要一种在显示器之间移动光标的方法。

#include "Xlib.h"
int main() {
  int delta_x = 5, delta_y = 5;
  Display *display = XOpenDisplay(":0.1");
  // move pointer relative to current position
  XWarpPointer(display, None, None, 0, 0, 0, 0, delta_x, delta_y);
  XCloseDisplay(display);
}

how can I set the mouse cursor in an X window in C under Linux with multi screens? I have 2 monitors (with different resolution) plugged to a single linux pc.
I used ":0.1" to address the second monitor. I run the application from monitor 1 keeping the mouse on the monitor 1 as well....as result mouse moves but don't jump on monitor 2.
If I manually put the mouse cursor on monitor 2 and run the application from monitor 1, mouse moves.

I need a way to move the cursor between monitors.

#include "Xlib.h"
int main() {
  int delta_x = 5, delta_y = 5;
  Display *display = XOpenDisplay(":0.1");
  // move pointer relative to current position
  XWarpPointer(display, None, None, 0, 0, 0, 0, delta_x, delta_y);
  XCloseDisplay(display);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梓梦 2024-10-13 13:34:22

您需要传递您希望指针移动到的显示器的根窗口的句柄:

    root = RootWindow(display, screennumber);
    XWarpPointer(display, None, root, 0, 0, 0, 0, x, y);

这里有一个完整的工作 C 示例:

http://www.ishiboo.com/~danny/Projects/xwarppointer/

可能有用:)

You need to pass the handle of the root window of the display you want the pointer to move to:

    root = RootWindow(display, screennumber);
    XWarpPointer(display, None, root, 0, 0, 0, 0, x, y);

There is a complete working C example here:

http://www.ishiboo.com/~danny/Projects/xwarppointer/

which may be of use :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文