Mimicking/faking a Mouse Click and Mouse Wheel using Qt

时间秒杀一切 提交于 2019-12-07 03:16:39

问题


How to mimic/fake a Mouse Click and Mouse Wheel using Qt? To be more specific, I want to click inside and outside the Qt application. Thanks in advance!


回答1:


If you want to simulate clicks on widgets inside your application, check out QTestEventList:

A QTestEventList can be populated with GUI events that can be stored as test data for later usage, or be replayed on any QWidget.

It lets you perform keypresses and various mouse events, but no wheel. Regardless, the source code should give cues on best practices for this sort of operation:

http://qt.gitorious.org/qt/qt/blobs/master/src/testlib/qtestmouse.h

http://qt.gitorious.org/qt/qt/blobs/master/src/testlib/qtestevent.h

OTOH, if you mean you want to simulate clicks outside your application (like icons on the desktop etc.) that's probably beyond the scope of the Qt API. To "take complete control over the mouse" on Windows there's this related question:

Simulating a mouse button click in Windows

...and might instead consider using an automation tool specifically designed for this task. Some options are the Windows Auto It!, the Mac's Automator, and the Web-based iMacros. You could even invoke such a tool from Qt as a QProcess.



来源:https://stackoverflow.com/questions/2004254/mimicking-faking-a-mouse-click-and-mouse-wheel-using-qt

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