#### Archived

This topic is now archived and is closed to further replies.

# Win32, keyboard/virtual keys -problem

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

## Recommended Posts

I need to convert virtual key codes into text strings, so instead of making a huge switch statement I decided to try some already existing functions:  char keyName[48]; GetKeyNameText(MapVirtualKey(VK_SPACE, 0) >> 16, keyName, 48)  The 16th to 23rd bit of the first parameter of GetKeyName() is the scan code, and MapVirtualKey() returns the scan code. This is the problem: GetKeyNameText returns zero (which means it has failed), and GetLastError also returns zero, which means that the last function was succesful. And nothing is added into the string. So whats going on here? any clues? [edited by - Jesper T on October 7, 2003 3:17:50 PM]

##### Share on other sites
Don''t input the scan code,
as the docs state you have to insert the LPARAM Parameter in GetKeyNameText; namely the exact lParam you receive from WM_KEYDOWN for example.

##### Share on other sites
Ah, yes, I read that too, but also

quote:

The function interprets the following portions of lParam:

Bits 16–23: Scan code.

Bit 24: Extended-key flag. Distinguishes some keys on an enhanced keyboard.

Bit 25: "Don't care" bit. The application calling this function sets this bit to indicate that the function should not distinguish between left and right CTRL and SHIFT keys, for example.

EDIT: NM, I found out whats wrong, I was shifting it the wrong way.. doh!

[edited by - Jesper T on October 8, 2003 6:49:29 AM]