从 WM_CHAR 消息获取虚拟键码
我从 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 位获取扫描码,
但我不确定如何:
- 从 lparam 中提取扫描码的值
- 将扫描码正确转换为 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:
- Extract the value of the scancode from lparam
- Translate the scan code to a VK_ correctly
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过一些混乱后,我设法使用以下代码提取虚拟密钥:
此代码获取 lParam 的地址作为无符号字符数组(一个字节的长度),然后使用指针算术来寻址第三个字节(位 16-23) :
此代码从扫描码转换为虚拟键:
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):
This code translates from the scancode to the virtual key:
也许您可能会使用 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.