Trouble Simulating Keystrokes

拈花ヽ惹草 提交于 2021-01-29 03:00:05

问题


I've used WIN32API calls in the past to simulate keystrokes without much trouble. Even now, at a superficial level, it seems to work. I'm using the Win32 SendMessage call to send a WM_KEYDOWN, WM_CHAR, WM_KEYUP message to an instance of Notepad.

And sure enough, whatever I send appears in Notepad.

But while using Spy++ to inspect the messages; I noticed that my sent Keystrokes were noticeably different than the keys I had actually typed or the ones created using Windows built-in on screen keyboard.

In Spy++ my single WM_KEYDOWN generates two lines:

<001> 00234 S WM_KEYDOWN nVirtKey:'W'....
<002> 00234 R WM_KEYDOWN

Pressing the W key for real (or using the OnScreenKeyboard) generates only a single line

<003> 00234 P WM_KEYDOWN nVirtKey:'W'...

If I expand these messages, I can see that 'S' represents Sent, R - 'Received', and P - 'Posted'.

Can anyone tell how I can more accurately simulate keyboard input programatically? I've matched the rest of the message (including the lParam value).


回答1:


I think you will need to use PostMessage rather than SendMessage. It's pretty much the same other than the way that the message is delivered to the reciever.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms644944%28v=vs.85%29.aspx



来源:https://stackoverflow.com/questions/12982513/trouble-simulating-keystrokes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!