Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert character to virtual key code

I have a string of values, and I want to simulate key press events in a window for each character.

I plan on sending WM_KEYDOWN, WM_CHAR, and WM_KEYUP events to the window (as that is what seems to happen whan a key is manually pressed).

Those messages require an int be sent in the wParam based on a table of virtual key codes. I can loop through the string and get each character, but how do I take that character and convert it to a value that corresponds to the virtual key code? Convert.ToInt32() does not work.

like image 878
Jeremy Avatar asked Dec 09 '22 15:12

Jeremy


1 Answers

VkKeyScanEx anyone? According to MSDN it:

"Translates a character to the corresponding virtual-key code and shift state."

(You could possibly also use VkKeyScan but beware that it has been superseded by VkKeyScanEx.)

like image 151
Andreas Magnusson Avatar answered Dec 26 '22 23:12

Andreas Magnusson