从 WM_KEYDOWN 消息中唯一识别密钥
我尝试使用 wParam 提供的虚拟键代码,但是效果不太好:
- 多个键映射到相同的键代码
- 某些键根本无法识别
- 虚拟键似乎适应了键盘布局(我不这样做) '不想要/需要)
然后我看到lParam会给我一个扫描码以及一个“扩展”标志,当这样计算时,它似乎会为键盘上的每个键产生不同的值:
value = (lParam & 0x01FF0000) >> 16;
这个值是否总是相同的对于键盘上的同一个键,即使跨各种键盘/系统?
I tried to use the virtual key code provided by wParam, however that didn't work very well:
- multiple keys mapped to the same key code
- some keys were not recognized at all
- virtual keys seemed to be adapted to the keyboard layout (which i don't want/need)
Then i saw that the lParam will give me a scancode along with an "extended" flag, which seem to produce a different value for every single key on the keyboard when calculated like this:
value = (lParam & 0x01FF0000) >> 16;
Will this value always be identical for the same key on the keyboard, even across various keyboards/systems?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不同键盘的扫描码可能不同。最好使用虚拟键码。来自 http://msdn.microsoft.com/en -us/library/ms646267(v=vs.85).aspx:
Scancodes can be different for different keyboards. Best to use virtual key codes. From http://msdn.microsoft.com/en-us/library/ms646267(v=vs.85).aspx: