简体   繁体   English

在Windows上,我们如何将虚拟键控代码转换为转换后的字符?

[英]On Windows, how do we convert a virtual key code to the shifted character?

I looked at MapVirtualKey() and ToAscii(). 我查看了MapVirtualKey()和ToAscii()。

MapVirtualKey() gives me only the unshifted character. MapVirtualKey()仅给我未移位的字符。 ToAscii() only works for vk codes that translate to ASCII values. ToAscii()仅适用于转换为ASCII值的vk代码。

I need to detect for example, "Ctrl + Shift + 3" as Ctrl active, Shift active and '#'. 我需要检测例如“ Ctrl + Shift + 3”作为Ctrl活动,Shift活动和'#'。

Any clues? 有什么线索吗?

This is how I finally did it: 这是我最终做到的方式:

case WM_KEYDOWN:
        GetKeyboardState(kbs);
        if(kbs[VK_CONTROL] & 0x00000080)
        {
            kbs[VK_CONTROL] &= 0x0000007f;
            ::ToAscii(p_wParam, ::MapVirtualKey(p_wParam, MAPVK_VK_TO_VSC), kbs, ch, 0);
            kbs[VK_CONTROL] |= 0x00000080;
        }
        else
            ::ToAscii(p_wParam, ::MapVirtualKey(p_wParam, MAPVK_VK_TO_VSC), kbs, ch, 0);

Then I get the states of all the modifier keys from kbs[]. 然后,我从kbs []获取所有修饰键的状态。

You can use GetKeyState() to determine key state of by providing virtual key code. 您可以使用GetKeyState()通过提供虚拟键代码来确定键的状态。 See also: GetKeyboardState() . 另请参见: GetKeyboardState()

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

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