Sign in to follow this  

Windows virtual key - string name

Recommended Posts

aftermath    100
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
IFooBar    906
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
Extrarius    1412
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

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