Convert character to virtual key code

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

I plan to send WM_KEYDOWN , WM_CHAR , and WM_KEYUP events to the window (since this happens when a key is pressed manually).

These messages require that int be sent to wParam based on the virtual keycode table . I can scroll the line and get each character, but how to take this character and convert it to a value corresponding to a virtual key code? Convert.ToInt32 () does not work.

+3
source share
7 answers

Sending WM_KEYDOWN / UP is difficult. The application itself already translates the WM_KEYDOWN message to WM_CHAR using the state of the modifier keys (Shift, Alt, Ctrl) and the keyboard layout. None of which you can control, you accidentally get the wrong character.

Just send WM_CHAR messages, set wparam to character code. No need to worry about lparam, several applications ever use it.

+3
source

VkKeyScanEx anyone? According to MSDN, this is:

"Translates the character into the corresponding virtual key code and switching state."

(You can also use VkKeyScan , but be careful that it has been replaced by VkKeyScanEx.)

+9

, ASCII . , "A" - 41. , A 0x41, (0x ).

0

, WM_KEYDOWN, WM_CHAR WM_KEYUP SendInput ( ) , , keybd_event ().

0
0
0

SendMessage WinAPI. SendMessage .

Oh , VK, MapVirtualKey - , .

0

Source: https://habr.com/ru/post/1752519/


All Articles