views:

688

answers:

1

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!

+2  A: 

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:

http://stackoverflow.com/questions/1740045/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.

Hostile Fork
+1 thanks Hostile Fork! I want to click outside application actually.
Viet
If you want to stimulate outside the app in an X11 environment, you can use Xnee: http://www.gnu.org/software/xnee/ .
e8johan
+1 thanks. I'm not an expert of X11.
Viet

related questions