[英]WM_KEYDOWN : how to use it?
I'm trying to send a key stroke to one application, through PostMessage. 我正试图通过PostMessage向一个应用程序发送一个关键笔划。 I am using too Spy++ to try to understand how to send the message, as I do not fully understand its inner workings.
我使用太Spy ++试图理解如何发送消息,因为我不完全理解它的内部工作原理。
In this picture, the first item(selected item) was made with an actual key stroke made by myself. 在这张照片中,第一个项目(选定项目)是由我自己制作的实际击键。 The one with a red elipse around it(below) was made with the following code:
它周围有一个红色椭圆(下图)的代码是用以下代码制作的:
WinApi.PostMessage(InsideLobbyHandle, WinApi.WM_KEYDOWN, (int)WinApi.VK_UP, 1);
I guess it must have something to do with the last PostMessage() parameter, but I can't figure out how it really works. 我想它必须与最后一个PostMessage()参数有关,但我无法弄清楚它是如何工作的。 I can see in the original key stroke the ScanCode = 48, and in mine its 0, and also fExtended is 1 and in mine is 0. How can I make it look the same?
我可以在原始按键中看到ScanCode = 48,并且在我的0中,并且fExtended是1,而我的是0.我怎么能让它看起来一样?
In http://msdn.microsoft.com/en-us/library/ms646280(VS.85).aspx I cannot understand the last parameter's working. 在http://msdn.microsoft.com/en-us/library/ms646280(VS.85).aspx我无法理解最后一个参数的工作原理。
Simulate keyboard input using SendInput , not PostMessage. 使用SendInput而不是PostMessage模拟键盘输入。
You can't simulate keyboard input with PostMessage . 您无法使用PostMessage模拟键盘输入 。
There are still some caveats with respect to keyboard state/async-state: 键盘状态/异步状态仍有一些警告 :
The SendInput function does not reset the keyboard's current state.
SendInput函数不会重置键盘的当前状态。 Therefore, if the user has any keys pressed when you call this function, they might interfere with the events that this function generates.
因此,如果用户在调用此函数时按下任何键,则可能会干扰此函数生成的事件。 If you are concerned about possible interference, check the keyboard's state with the GetAsyncKeyState function and correct as necessary.
如果您担心可能的干扰,请使用GetAsyncKeyState函数检查键盘的状态,并根据需要进行更正。
The lParam for the WM_KEYDOWN Notification is specified in terms of the bits of the field: WM_KEYDOWN通知的lParam是根据字段的位数指定的:
A warning: Any solution you build based around PostMessage is going to be very brittle. 警告:您基于PostMessage构建的任何解决方案都将非常脆弱。
看一下http://inputsimulator.codeplex.com ,它包装了Kevin提到的SendInput
方法
In Spy++ if you right click on the highlighted (logged message) entry and look at its properties, You can see the exact value of the lParam. 在Spy ++中,如果右键单击突出显示的(已记录的消息)条目并查看其属性,则可以看到lParam的确切值。 You can then use that as your lParam to ensure that the PostMessage leads to similar effects, as the manual action did.
然后,您可以将其用作lParam,以确保PostMessage产生与手动操作类似的效果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.