PDA

View Full Version : Mouseclick outside from widget



binio
22nd March 2013, 01:12
Hello,

i want set and click the cursor outside from my Application (e.k. a game in windowsmode or a word dokument).

I have tested

QCursor::setPos(10,10);
to set my Mouseposition. Its work, the mousposition are outside on my widget and application(my application is only 1 px big).
but the click doesnt work :(

I have use/testing


#include <Windows.h>
...
mouse_event(MOUSEEVENTF_LEFTDOWN,0, 0, 0,0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0,0);

or



CONFIG += qtestlib




#include <QtTest/QTest>
...
QTestEventList *eventList=new QTestEventList();
eventList->addDelay(2000);
eventList->addMouseMove(QPoint(15,35));
eventList->addMouseClick(Qt::LeftButton,Qt::NoModifier,QPoint (15,35));
eventList->simulate(this);


but nothing work :(

Idont know what i can do.... can someone help me please ?

lanz
22nd March 2013, 06:07
AFAIK there's no way Qt simulate window manager events (like mouse click) outside your own app.
You need to ask window manager to do it for you (calling SendInput (http://msdn.microsoft.com/ru-RU/library/windows/desktop/ms646310(v=vs.85).aspx) on Windows or XSendEvent (http://tronche.com/gui/x/xlib/event-handling/XSendEvent.html) on X11.

binio
23rd March 2013, 23:26
I have think that


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

is to say the Windows API what they must do maybe outside my application

lanz
25th March 2013, 05:53
Yeah, I missed it.

So, maybe you should try adding MOUSEEVENTF_ABSOLUTE flag?