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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With