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

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

问题描述

我想击键发送到一个应用程序,通过PostMessage的。我使用过间谍++试图了解如何发送消息,因为我不完全了解它的内部运作。

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.

在这幅画中,第一项(所选项目)与我自己做一个实际的键击的。与它周围的(下面)与以下code制成的红色elipse所述一个:

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的()的参数,但我无法弄清楚它是如何真正起作用。我可以在原来的击键看到扫描code = 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 /库/ 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的的键盘输入。

还有<一个href=\"http://msdn.microsoft.com/en-us/library/ms646267%28VS.85%29.aspx#%5Fwin32%5FSimulating%5FInput\">some注意事项对于以键盘状态/异步状态:

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

该SendInput函数不会重置
  键盘的当前状态。
  因此,如果用户有任何键
  pressed当你调用这个函数,
  它们可能会干扰事件
  这个函数生成。如果你
  正在关注可能
  干扰,检查键盘的
  状态与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.


在lParam中的 WM_KEYDOWN通知而言指定字段的位:

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


  • 第16位是重复计数

  • 接下来的8位是扫描code

  • 下一个位为1的扩展键,否则为0

  • 接下来的4位是保留的,必须在0

  • 下位始终为0(为WM_KEYDOWN)

  • 接下来一位是previous国家重点

  • 的最后一位始终为0(为WM_KEYDOWN)

一个警告:建立基于各地PostMessage的任何解决方案将是非常脆弱

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

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

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