c++ - How can I simulate all mouse and keyboard events in Qt that works on Linux and Windows? -
problem: have device send me commands (e.g: 1,2,3,...), want simulate mouse , keyboard events according received commands in both linux os , windows os.
i worked bool qcoreapplication::postevent(qobject *receiver, qevent *event, int priority = qt::normaleventpriority)
don't know receiver pass , has problem mousemove
action it.
i found help works in linux os, have problem approach in windows os. there approach works in both os?
thanks attention.
you can set mouse position :
qcursor::setpos(qpoint(10,10));
also mouse click simulation done :
qmouseevent * event1 = new qmouseevent ((qevent::mousebuttonpress), qpoint(10,10), qt::leftbutton, qt::leftbutton, qt::nomodifier ); qapp->postevent((qobject*)mywidget,(qevent *)event1); qmouseevent * event2 = new qmouseevent ((qevent::mousebuttonrelease), qpoint(10,10), qt::leftbutton, qt::leftbutton, qt::nomodifier ); qapp->postevent((qobject*)mywidget,(qevent *)event2);
sending key event widget :
qkeyevent *event = new qkeyevent ( qevent::keypress, qt::key_enter, qt::nomodifier); qcoreapplication::postevent (mywidget, event);
Comments
Post a Comment