Search code examples
c++linuxqtx11xlib

How to do a fake mouse wheel move in linux


I'm trying to simulate keyboard and mouse events, i've successfully made fake keyboard keydown, keyup. Fake mouse button down, up and fake mouse move, but i don't found how to do fake mouse wheel move, can someone explain to me a simple way to do this in c++?

Mouse Move and Mouse button press:

Display *dpy = XOpenDisplay(NULL);
XTestFakeMotionEvent(dpy, -1, 50, 50, 0);
XTestFakeButtonEvent(dpy, Button1, true, 0);
XTestFakeButtonEvent(dpy, Button1, false, 0);
XFlush(dpy);
XCloseDisplay(dpy);

Keyboard key press:

Display *dpy = XOpenDisplay(NULL);
unsigned int keycode = XKeysymToKeycode(dpy, XK_Super_L);
XTestFakeKeyEvent(dpy, keycode, true, 0);
XTestFakeKeyEvent(dpy, keycode, false, 0);
XFlush(dpy);
XCloseDisplay(dpy);

Solution

  • Isn't a mousewheel step on Linux just another button press? I can't test this for you now, but I recall on my system that rolling the mousewheel simply generated button events. You can test this on your system by running the program xev which displays X input events.