因为在 Windows 中,windows.h 中有一个函数 setCursorPos 用于控制光标位置。在 ubuntu 中如何做到这一点?
答案1
如果你使用 X11,这是解决方案
Display *dpy;
Window root_window;
dpy = XOpenDisplay(0);
root_window = XRootWindow(dpy, 0);
XSelectInput(dpy, root_window, KeyReleaseMask);
XWarpPointer(dpy, None, root_window, 0, 0, 0, 0, 100, 100);
XFlush(dpy); // Flushes the output buffer, therefore updates the cursor's position. Thanks to Achernar.
来源:https://stackoverflow.com/questions/2433447/how-to-set-mouse-cursor-position-in-c-on-linux