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.
Here are few methods in different programming languages to print ASCII value of a given character : Python code using ord function : ord() : It converts the given string of length one, returns an integer representing the Unicode code point of the character.
ASCII value of uppercase alphabets – 65 to 90. ASCII value of lowercase alphabets – 97 to 122.
Then it looks for a ASC(63) = “?”, then it trims the cell down to without the black diamond. The reason this work is when it loops through each digit in the string, it will recognize the black diamond as ASC = 63.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With