How to do a fake mouse wheel move in linux

2019-07-16 04:24发布

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);

标签: c++ linux qt x11 xlib
1条回答
相关推荐>>
2楼-- · 2019-07-16 04:45

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.

查看更多
登录 后发表回答