Convert sequence of System.Windows.Forms.Keys to a Char
Is there a way to convert a sequence of keystrokes represented by the Keys enum (i.e. System.Windows.Forms.Keys
) in a Char. For example: Keys.Oem4
and then Keys.A
yields the char á
. It must exist somewhere in the WinAPI, because Windows does that for me, when I press keys inside a text-box... I just don't know where. Please help! thanks.
EDIT:
What I want is to record the user 开发者_如何转开发input keys, and later translate the sequence of keys to characters, without the user having to type everything again, something like a macro.
The most straight forward way to do this is to first convent the Key
value into a Virtual Key code. This is done via KeyInterop.VirtualKeyFromKey. You can then PInvoke into the MapVirtualKey function to convert the key into a char.
I think it might be internal to Windows. The best info I can find is here:
https://learn.microsoft.com/en-us/windows/win32/inputdev/using-keyboard-input
Basically the window receives a WM_CHAR
message after TranslateMessage
is called on the WM_KEYDOWN
etc. messages received in the message loop. The WM_CHAR
message then contains the character you want.
精彩评论