从 WM_CHAR 消息获取虚拟键码

发布于 2024-12-08 18:01:23 字数 473 浏览 0 评论 0原文

我从 WM_CHAR 和 WM_KEYDOWN 消息中获取文本输入和按键输入

我想要做的是过滤掉 WM_CHAR 消息,这些消息与绑定到启用您输入文本的控件的键具有相同的 VK_ 代码。

EG:游戏使用~ 要启用控制台,键绑定是通过 VK_OEM3 和 WM_KEYDOWN 完成的,但是输入到控制台的文本需要来自 WM_CHAR 的文本。

由于 WM_KEYDOWN 首先发生,控制台被激活,然后 ~ 的 WM_CHAR 被发送到我不想要的控制台缓冲区。

我认为防止这种情况的最佳方法是将 WM_CHAR 中的 VK_ 与控件的绑定键进行比较并将其过滤掉。

有没有办法从 WM_CHAR 消息中获取 VK_ ?

我读到您可以从 Lparam 的第 16-23 位获取扫描码,

但我不确定如何:

  1. 从 lparam 中提取扫描码的值
  2. 将扫描码正确转换为 VK_

I am getting text input and keypress input from the WM_CHAR and WM_KEYDOWN messages

What I want to do is filter out WM_CHAR messages the have the same VK_ code as the key that is bound to enable the control that you enter text in.

EG: Game uses ~ to enable console, key binding is done via VK_OEM3 and WM_KEYDOWN, but text input into the console needs text from WM_CHAR.

As the WM_KEYDOWN happens first, the console is activated, then a WM_CHAR of ~ is sent to the console buffer which I don't want.

I figured the best way to prevent this is to compare the VK_ from the WM_CHAR to the bound key for the control and filter it out.

Is there a way to get the VK_ from a WM_CHAR message?

I read that you can get the scancode out of Lparam at bits 16-23

But am unsure how to:

  1. Extract the value of the scancode from lparam
  2. Translate the scan code to a VK_ correctly

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神经大条 2024-12-15 18:01:23

经过一些混乱后,我设法使用以下代码提取虚拟密钥:

此代码获取 lParam 的地址作为无符号字符数组(一个字节的长度),然后使用指针算术来寻址第三个字节(位 16-23) :

  unsigned char scancode = ((unsigned char*)&lParam)[2];

此代码从扫描码转换为虚拟键:

  unsigned int virtualKey = MapVirtualKey(scancode,MAPVK_VSC_TO_VK);

After some messing around I managed to extract the virtual key with the following code:

This code gets the address of lParam as a unsigned char array (one byte of length), then uses pointer arithmatic to address the 3rd byte (bits 16-23):

  unsigned char scancode = ((unsigned char*)&lParam)[2];

This code translates from the scancode to the virtual key:

  unsigned int virtualKey = MapVirtualKey(scancode,MAPVK_VSC_TO_VK);
居里长安 2024-12-15 18:01:23

也许您可能会使用 MapVirtualKey

我不确定如何从 lparam 中提取扫描码,因为文档没有说明 - 要么获取整个 lparam 并计算该函数知道要查看哪些位,要么使用位域结构并从中获取正确的位。我认为这些方法中的一种应该有效 - 尝试这两种方法应该不难。

Perhaps you migh use MapVirtualKey.

I am not sure how to extract scancode from lparam as documentation does not state that - either get entire lparam and count that this function knows which bits to look at, or use bitfield struct and just get right bits out of it. I think on of those methods should work - trying both shouldn't be difficult.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文