【问题标题】:Mouse cursor position in C on multi screen system多屏幕系统上 C 中的鼠标光标位置
【发布时间】:2010-12-08 08:29:03
【问题描述】:

如何在多屏幕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);
}

【问题讨论】:

    标签: c++ c linux mouse x11


    【解决方案1】:

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

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

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

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

    这可能有用:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多