MapVirtualKeyEx & multimedia keyboard errors

This topic is 3057 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I'm attempting to map keycodes to scancodes in an effort to get the string representation of the key. The code works for the desktop keyboards that I've tested, yet on my laptop (which has f1-f12 buttons that do things like adjust volume) they seem to be mapping to incorrect keys. For example, f3 would map to the 'J' button. f4, maybe the 'D' key. I cannot for the life of me figure out what is wrong. Does anyone have any ideas? Here is a snippet of what I've got going on here...
        unsigned int scanCode = MapVirtualKeyEx(keyCode, 0, GetKeyboardLayout(0));
DWORD lastError = GetLastError();

switch (keyCode)
{
case KC_LEFT: case KC_UP: case KC_RIGHT: case KC_DOWN: // arrow keys
case KC_PAGEUP: case KC_PAGEDOWN: // page up and page down
case KC_END: case KC_HOME:
case KC_INSERT: case KC_DELETE:
case KC_NUMLOCK:
{
scanCode |= 0x100; // set extended bit
break;
}
}

GetKeyNameTextW(scanCode << 16, keyName, sizeof(buffer));

So when I press the function keys on the multimedia keyboard I get the keycodes in the 173-179 range. I'm assuming the resulting 'J' or 'D' mapping is due to an overflow, but I'm not sure. Thanks in advance!

1. 1
2. 2
3. 3
Rutin
22
4. 4
JoeJ
16
5. 5

• 14
• 29
• 13
• 11
• 11
• Forum Statistics

• Total Topics
631774
• Total Posts
3002290
×