Sign in to follow this  

Windows virtual key - string name

This topic is 4858 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

Does anyone know how to translate Windows virtual key codes into strings (i.e.: VK_SHIFT => "Shift", VK_NUM9 => "Num 9") without having a large table and writing the strings myself? There is the function MapVirtualKey but it seems to give me whack results. Does anyone know if there is any already-written code out there that does this? Thanks a pantsfull!

Share this post


Link to post
Share on other sites
MapVirtualKey dosen't give you a string for your virtual key. It gives you a scan code corresponding to the virtual key code.

You can probably do what you want by using '#' and a bit of indexing..


#define STR_VK_HELPER( vk ) (#vk)
#define StrVK( vk ) StrVK( STR_VK_HELPER( vk ) )
const char* StrVK( const char* vk )
{
return vk + 3;
// Or put it into a string and return that.

// All characters will of course be capitalized, you can
// uer the tolower/toupper to fix that though if you must.
}

Share this post


Link to post
Share on other sites
MapVirtualKey and GetKeyNameText might perhaps do it, or is that what you've already tried without success?

IFooBar: The problem with that is that it only works if you make a table of every VK_ code. You can't do something like StrVK(VariableThatHoldsTheVirtualKeyCodeThatTheUserJustPressed).

Share this post


Link to post
Share on other sites
Sign in to follow this