Sign in to follow this  
wizard341

MapVirtualKeyEx & multimedia keyboard errors

Recommended Posts

wizard341    144
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_DIVIDE: // numpad slash
			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!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this