Reputation: 328
I'm trying to create a simple bot in Qt and need therefor a way of simulating keyboard presses OUTSIDE the Qt application itself.
I've successfully made this possible by using the "old" keybd_event
keybd_event(Qt::Key_A,0,0, 0); // Pressing the 'A-button"
and that works out fine. But i can't make it when i'm trying to execute a 'select all' command which needs two buttons to be pressed at once.
As i researched the problem on Google i was refereed to the 'SendInput' function with the message 'This function (keybd_event) has been superseded. Use SendInput instead.'
The problem now is that I've little knowledge of windows API and especially in the contex of "Qt" and would like guidance on how to get started.
Upvotes: 1
Views: 3912
Reputation: 12547
keybd_event
is actually not Qt function, but part of Windows Api.
Both keybd_event
and SendInput
allow you to send press event and release event. If you want to send combination ctrl+A
you should send events as follows:
press Ctrl -> press A -> release A -> release Ctrl
If you want to use keybd_event
, you need to call it 4 times subsequently, if you want to use SendInput
, you can make an array of 4 events.
You should use keyboard codes from Windows API to simulate keyboard events, while Qt's codes may coincide with Microsoft's.
Also you should understand that this solution has nothing to do with Qt, it Windows specified.
You just found all links to docs you would need, I think you should start studing it and ask more concrete questions, if you would have any problems.
Upvotes: 1