How to do a fake mouse wheel move in linux

≡放荡痞女 提交于 2019-12-23 20:08:09

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/14793338/how-to-do-a-fake-mouse-wheel-move-in-linux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!