Jump to content

  • Log In with Google      Sign In   
  • Create Account


Getting the key name for a VK constant


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 SyncViews   Members   -  Reputation: 319

Like
1Likes
Like

Posted 15 June 2011 - 11:50 AM

Given a VK constant value (say VK_CONTROL, 0x11) I want to get a human readable string for display to the end user, e.g. "Ctrl". Previously I have done this with an array of strings so that I could do like "keyNames[VK_CONTROL]". However some of the symbol keys move around with keyboard layouts and I suspect there are some other cases I overlooked. And it seems to me that using a hardcodded table for this sort of thing is the wrong way to do it anyway.

I suspect that the Windows API contains a function to convert from a VK code to a "whats printed on the physical keyboard" string, however I have not been able to find it :(

Sponsor:

#2 yewbie   GDNet+   -  Reputation: 665

Like
0Likes
Like

Posted 15 June 2011 - 01:04 PM

Given a VK constant value (say VK_CONTROL, 0x11) I want to get a human readable string for display to the end user, e.g. "Ctrl". Previously I have done this with an array of strings so that I could do like "keyNames[VK_CONTROL]". However some of the symbol keys move around with keyboard layouts and I suspect there are some other cases I overlooked. And it seems to me that using a hardcodded table for this sort of thing is the wrong way to do it anyway.

I suspect that the Windows API contains a function to convert from a VK code to a "whats printed on the physical keyboard" string, however I have not been able to find it :(


I looked for something like this myself and I couldn't find anything so I would also be interested in this information =)

#3 typedef struct   Members   -  Reputation: 230

Like
0Likes
Like

Posted 15 June 2011 - 01:25 PM

You can get the character by using MapVirtualKey, but that's not exactly what you're looking for obviously (it wouldn't do anything for Control).

I'm pretty sure this is outside the scope of the Windows API and you should just keep doing it the way you're doing it.
Anthony Umfer

#4 Endurion   Crossbones+   -  Reputation: 3331

Like
1Likes
Like

Posted 15 June 2011 - 11:26 PM

This is probably what you're looking for: MSDN

However I find your statement that virtual keys shift around with keyboard layouts weird. That's the whole point of the virtual keys, they are defined constants and do NOT move around. The layout adjustment is done on a lower level, so a fixed string array should work fine.
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

#5 SyncViews   Members   -  Reputation: 319

Like
0Likes
Like

Posted 16 June 2011 - 03:37 AM

Well I don't know about the physical locations of a given VK_ code, allthough I guess they also move around given that a UK keyboard has a key between Shift annd 'Z' while US ones don't, instead having a key beteen backspace and return but what symbols some of the VK_OEM_* codes represent definatly changes.

e.g. Apperently VK_OEM_3 on a US keyboard is the ` ~ key. However for me on a UK layout those are not even on the same key. ` is to the left of '1' with the ¬ and ¦ (shift and alt gr respectivily) and uses the VK_OEM_8 code, and ~ is a shifted # to the left of the return key using VK_OEM_7. Not sure what VK_OEM_8 is meant to be for US users, but VK_OEM_7 is listed as ' ". Well ' is what VK_OEM_3 here (with @ as the shifted symbol) and " is a shifted 2.

Havnt tested yet but I'm guessing MapVirtualKey can deal with all the VK_OEM's in a suitable manner. Things like ctrl are always ctrl so I'm not too worried about those ones :)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS