Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASCII character from VK_Code

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.

like image 978
Kevin Meier Avatar asked Sep 04 '11 13:09

Kevin Meier


People also ask

How do I get the Ascii code for a character?

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.

What is the Ascii code for A to Z?

ASCII value of uppercase alphabets – 65 to 90. ASCII value of lowercase alphabets – 97 to 122.

What ASCII 63?

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.


1 Answers

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.

like image 78
Jim Mischel Avatar answered Sep 20 '22 15:09

Jim Mischel