开发者

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

I looked at MapVirtualKey() and ToAscii().

MapVirtualKey() gives me only the unshifted character. ToAscii() only works for vk codes that translate to ASCII values.

I need t开发者_运维知识库o detect for example, "Ctrl + Shift + 3" as Ctrl active, Shift active and '#'.

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[].


You can use GetKeyState() to determine key state of by providing virtual key code. See also: GetKeyboardState().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜