简体   繁体   English

如何通过WinUser.h获取当前的虚拟密钥代码?

[英]How to get the current Virtual Key Code via WinUser.h?

I am using WinUser.h and need to know if there is a simple way of getting the virtual key of whatever key is pressed on the keyboard. 我正在使用WinUser.h,需要知道是否有一种简单的方法来获取键盘上按下的任何键的虚拟键。

I have tried GetAsyncKeyState() and it works fine, but I need the actual virtual key to be returned rather than running through a long series of GetAsyncKeyState() calls to check every key on the keyboard. 我已经尝试过GetAsyncKeyState(),并且工作正常,但是我需要返回实际的虚拟键,而不是通过一系列长的GetAsyncKeyState()调用来检查键盘上的每个键。

I am essentially creating a system that allows users to map their controls, which is why it would be more ideal if I could get the virtual key and then run a check against keys that are not allowed. 我本质上是在创建一个允许用户映射其控件的系统,这就是为什么如果我可以获取虚拟密钥然后对不允许的密钥进行检查,则更为理想的原因。

Also, C++ is the language being used. 同样,C ++是所使用的语言。 Thank you for any help in this matter. 多谢您提供协助。

You almost certainly want to response to the WM_KEYDOWN/WM_KEYUP or (more likely) WM_CHAR messages. 您几乎肯定希望响应WM_KEYDOWN / WM_KEYUP或(更可能是)WM_CHAR消息。 WM_CHAR give you the result after TranslateMessage does its job, so it's what you usually want. WM_CHAR在TranslateMessage完成其工作后为您提供结果,所以这通常是您想要的。 It'll give you both the translated virtual key code and the scan code of the key that was pressed, in case you need that as well. 如果需要的话,它还会为您提供翻译后的虚拟键码所按键的扫描码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM