I have a small WIN32 C-Application in which i work with the KBDLLHOOKSTRUCT
structure. This structure contains the VK-Code for a pressed key.
I try to convert this to an ASCII-Character. For this i use the Function MapVirtualKey
, which works well.
The only problem is, that one VK-Code can stay for multiple chars. Example:
On my keyboard (Swiss-German) exists the key-char .. If i press Shift+. then it creates a :
. The VK-Code is the same. Thats no problem, and i can also check if Shift is pressed or Caps Lock is activated.
My only problem is: How can i get the char ':'? I need a function like this:
GetKeyChar(vkCode, shift)
I need this to get the "normal" and the "shifted" value of the keyboard. Of course i could hardcode this, but i don't like to do it on this way.
The problem is that the KBDLLHOOKSTRUCT
doesn't have all the information you need in order to do the translation. You get a message every time a key is pressed. So for Shift+X, you'll get an input message saying that the Shift key was pressed, and another message saying that the "X" key was pressed.
You need to call GetKeyboardState in order to get the state of the Shift, Alt, Ctrl, (and perhaps other) keys. Then call ToAsciiEx
or ToUnicodeEx
.