Reputation: 47
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";
// & if the key pressed was CTRL then keyPressed = "CTRL";
Upvotes: 1
Views: 1010
Reputation: 70701
You can pass in the lParam
value from WM_KEYDOWN
to GetKeyNameText
and it will return the key name for you.
Upvotes: 2