VK_Code 中的 ASCII 字符
我有一个小型 WIN32 C 应用程序,在其中使用 KBDLLHOOKSTRUCT
结构。该结构包含按键的 VK 代码。
我尝试将其转换为 ASCII 字符。为此,我使用函数 MapVirtualKey< /code>
,效果很好。
唯一的问题是,一个 VK 代码可以保留多个字符。 示例:
在我的键盘(瑞士-德语)上存在键字符 .。如果我按 Shift+. 然后它会创建一个 :
。 VK 代码是相同的。没问题,我还可以检查 Shift 是否已按下或 Caps Lock 是否已激活。
我唯一的问题是:我怎样才能得到字符':'? 我需要这样的函数:
GetKeyChar(vkCode, shift)
我需要它来获取键盘的“正常”和“移位”值。当然,我可以对此进行硬编码,但我不喜欢以这种方式进行。
I have a small WIN32 C-Application in which i work with the KBDLLHOOKSTRUCT
structure. This structure contains the VK-Code for a pressed key.
I try to convert this to an ASCII-Character. For this i use the Function MapVirtualKey
, which works well.
The only problem is, that one VK-Code can stay for multiple chars.
Example:
On my keyboard (Swiss-German) exists the key-char .. If i press Shift+. then it creates a :
. The VK-Code is the same. Thats no problem, and i can also check if Shift is pressed or Caps Lock is activated.
My only problem is: How can i get the char ':'?
I need a function like this:
GetKeyChar(vkCode, shift)
I need this to get the "normal" and the "shifted" value of the keyboard. Of course i could hardcode this, but i don't like to do it on this way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
问题是
KBDLLHOOKSTRUCT
没有进行翻译所需的所有信息。每次按下某个键时您都会收到一条消息。因此,对于 Shift+X,您将收到一条输入消息,表明已按下 Shift 键,并收到另一条消息,表明已按下“X”键。您需要依次调用 GetKeyboardState获取 Shift、Alt、Ctrl(或许还有其他)键的状态。然后调用
ToAsciiEx
或ToUnicodeEx
。The problem is that the
KBDLLHOOKSTRUCT
doesn't have all the information you need in order to do the translation. You get a message every time a key is pressed. So for Shift+X, you'll get an input message saying that the Shift key was pressed, and another message saying that the "X" key was pressed.You need to call GetKeyboardState in order to get the state of the Shift, Alt, Ctrl, (and perhaps other) keys. Then call
ToAsciiEx
orToUnicodeEx
.您正在寻找
ToUnicode
,返回该按键生成的 unicode 字符。You're looking for
ToUnicode
, which returns the unicode character generated by that keypress.您正在寻找的函数是:ToAscii、ToAsciiEx、ToUnicode、ToUnicodeEx。
The functions you are looking for are: ToAscii, ToAsciiEx, ToUnicode, ToUnicodeEx.
short VkKeyScan(char ch)
API 已包含班次信息。它将字符转换为虚拟键代码和移位状态。请参阅:将字符转换为相应的虚拟键代码
short VkKeyScan(char ch)
API has contained the shift information. It translate char to virtual-key code and shift state.See this: Convert character to the corresponding virtual-key code