Mouse cursor position in C on multi screen system
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);
}
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 :)
链接地址: http://www.djcxy.com/p/49218.html下一篇: 多屏幕系统中C鼠标光标位置