故障模拟击键 [英] Trouble Simulating Keystrokes
问题描述
我过去曾经使用WIN32API调用来模拟击键而没有太多麻烦.即使到现在,从表面上看,它似乎仍然有效.我正在使用Win32 SendMessage调用将WM_KEYDOWN,WM_CHAR,WM_KEYUP消息发送到记事本实例.
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.
但是在使用Spy ++检查消息时;我注意到,我发送的击键与我实际键入的键或使用屏幕键盘上内置的Windows创建的键明显不同.
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.
在Spy ++中,我的单个WM_KEYDOWN生成两行:
In Spy++ my single WM_KEYDOWN generates two lines:
<001> 00234 S WM_KEYDOWN nVirtKey:'W'....
<002> 00234 R WM_KEYDOWN
实际按下W键(或使用OnScreenKeyboard)仅生成一行
Pressing the W key for real (or using the OnScreenKeyboard) generates only a single line
<003> 00234 P WM_KEYDOWN nVirtKey:'W'...
如果我展开这些消息,我会看到"S"代表已发送,R-已接收",P-已发布".
If I expand these messages, I can see that 'S' represents Sent, R - 'Received', and P - 'Posted'.
有人可以告诉我如何通过编程更准确地模拟键盘输入吗?我已经匹配了其余消息(包括lParam值).
Can anyone tell how I can more accurately simulate keyboard input programatically? I've matched the rest of the message (including the lParam value).
推荐答案
我认为您需要使用 PostMessage
而不是 SendMessage
.除了将邮件传递到收件人的方式外,几乎是相同的.
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/zh-CN/library/windows/desktop/ms644944%28v=vs.85%29.aspx
这篇关于故障模拟击键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!