开发者

Detecting non-character press from WM_KEYDOWN message

Is there a function in win32 that can take the Virtual Key code for the CTRL, ALT or capslock key & return a string saying "CTRL", "ALT", "CAPSLOCK"?

I can only receive WM_KEYDOWN messages but not WM_CHAR messages. I know I can determine what character key has been pressed by passing the Virtual Key code to the function ToUnicode() & it will tell me what character key has been pressed.

But that function returns nothing if I pass the CTRL virtual key code.

char keyPressed[256];
KBDLLHOOKSTRUCT kbdStruct = *((KBDLLHOOKSTRUCT*)lParam);
GetKeyboardState((PBYTE)&keyState);
ToUnicode(kbdStruct.vkCode, kbdStruct.scanCode, (PBYTE)&keyState, (LPWSTR)&keyPressed, sizeof(keyPressed) / 2, 0);    
// so if the key pressed was 'a' then keyPressed = "a";
// &开发者_StackOverflow社区; if the key pressed was CTRL then keyPressed = "CTRL";


You can pass in the lParam value from WM_KEYDOWN to GetKeyNameText and it will return the key name for you.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜