Skip to content

Instantly share code, notes, and snippets.

@aliva
Created August 16, 2012 18:17
Show Gist options
  • Save aliva/3372331 to your computer and use it in GitHub Desktop.
Save aliva/3372331 to your computer and use it in GitHub Desktop.
move mouse pointer to given position in linux
#include <X11/Xlib.h>
#include <iostream>
#include <unistd.h>
int main(void) {
Display* dpy = XOpenDisplay(0);
int scr = XDefaultScreen(dpy);
Window root_window = XRootWindow(dpy, scr);
int height = DisplayHeight(dpy, scr);
int width = DisplayWidth(dpy, scr);
std::cout << "Screen size : " << width << "x" << height << std::endl;
float m = (float)height/(float)width;
int j;
for(int i=0; i<width; i++){
j = m*i;
XWarpPointer(dpy, None, root_window, 0, 0, 0, 0, i, j);
XFlush(dpy);
usleep(50);
}
}
@iamcopper
Copy link

iamcopper commented Nov 26, 2021

build command:
g++ move-cursor-linux.cpp -o move-cursor-linux -lX11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment