1

我正在尝试在 Qt 中创建一个简单的机器人,因此需要一种在 Qt 应用程序本身之外模拟键盘按下的方法。

我已经通过使用“旧”keybd_event 成功地实现了这一点

keybd_event(Qt::Key_A,0,0, 0); // Pressing the 'A-button"

效果很好。但是当我尝试执行需要同时按下两个按钮的“全选”命令时,我无法做到。

当我在谷歌上研究这个问题时,我被引用到' SendInput '函数,并显示消息'这个函数(keybd_event)已被取代。改用 SendInput。

现在的问题是我对 Windows API 知之甚少,尤其是在“Qt”的上下文中,并且希望获得有关如何入门的指导。

4

1 回答 1

1

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.

于 2012-01-21T15:44:07.563 回答