Jump to content
  • Advertisement
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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_DIVIDE: // numpad slash
			case KC_NUMLOCK:
				scanCode |= 0x100; // set extended bit

        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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!