Generate mouse events using Qt framework

两盒软妹~` 提交于 2020-01-05 10:10:41

问题


I am using Qt framework and I would like to generate mouse events outside my application window.

So far I managed to move the mouse pointer using:

QGuiApplication::overrideCursor()->setPos(x,y);

How can I also generate left mouse button click, middle button click, right button click and mouse wheel movement?


回答1:


A few years ago i wrote a drivers for GUI testing (for mouse and keyboard). Drivers are developed for Windows, Linux and MacOS X. You can look at here. There is a OS depended MouseDriver implementation for Windows. Also you can see other implementations. This is a open source project, you can use it code for free.




回答2:


There's no way to do that with Qt. Use APIs specific for your target platform.




回答3:


Addition to first answer. For example in Windows:

Click:

mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP,x,y,0,0);

Wheel:

mouse_event(MOUSEEVENTF_WHEEL, 0, 0, WHEEL_DELTA, NULL);

More information: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646260(v=vs.85).aspx

Use also qt macros:

#ifdef Q_WS_X11
//Linux
#endif
#ifdef Q_WS_WIN
//Windows
#endif
#ifdef Q_WS_MACX
//Mac
#endif

More about macros: http://qt-project.org/doc/qt-5/qtglobal.html

QSysInfo: http://qt-project.org/doc/qt-5/qsysinfo.html



来源:https://stackoverflow.com/questions/26267668/generate-mouse-events-using-qt-framework

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