WM_KEYDOWN :如何使用它? [英] WM_KEYDOWN : how to use it?

查看:29
本文介绍了WM_KEYDOWN :如何使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 PostMessage 向一个应用程序发送击键.我也使用 Spy++ 来尝试了解如何发送消息,因为我不完全了解其内部工作原理.

I'm trying to send a key stroke to one application, through PostMessage. I am using too Spy++ to try to understand how to send the message, as I do not fully understand its inner workings.

在这张图片中,第一个项目(选定项目)是由我自己实际击键制作的.周围有一个红色椭圆的那个(下图)是用以下代码制作的:

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);

我想它一定与最后一个 PostMessage() 参数有关,但我无法弄清楚它是如何工作的.我可以在原始击键中看到 ScanCode = 48,我的为 0,fExtended 为 1,我的为 0.我怎样才能让它看起来一样?

I guess it must have something to do with the last PostMessage() parameter, but I can't figure out how it really works. 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?

http://msdn.microsoft.com/en-us/library/ms646280(VS.85).aspx 我无法理解最后一个参数的工作原理.

In http://msdn.microsoft.com/en-us/library/ms646280(VS.85).aspx I cannot understand the last parameter's working.

推荐答案

使用 SendInput,而不是 PostMessage.

Simulate keyboard input using SendInput, not PostMessage.

您不能使用 PostMessage 模拟键盘输入.

仍有一些注意事项关于键盘状态/异步状态:

There are still some caveats with respect to keyboard state/async-state:

SendInput 函数不会重置键盘的当前状态.因此,如果用户有任何密钥调用此函数时按下,他们可能会干扰事件这个函数生成的.如果你担心可能干扰,检查键盘的状态与 GetAsyncKeyState功能并根据需要进行更正.

The SendInput function does not reset the keyboard's current state. 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.

<小时>

WM_KEYDOWN 通知的 lParam 是根据字段的位指定:


The lParam for the WM_KEYDOWN Notification is specified in terms of the bits of the field:

  • 前 16 位是重复次数
  • 接下来的 8 位是扫描码
  • 对于扩展密钥,下一位为 1,否则为 0
  • 接下来的 4 位是保留的,必须为 0
  • 下一位总是 0(对于 WM_KEYDOWN)
  • 下一位是之前的关键状态
  • 最后一位总是 0(对于 WM_KEYDOWN)

警告:您基于 PostMessage 构建的任何解决方案都将非常脆弱.

A warning: Any solution you build based around PostMessage is going to be very brittle.

这篇关于WM_KEYDOWN :如何使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆