Convert sequence of System.Windows.Forms.Keys to a Char

无人久伴 提交于 2019-12-24 03:53:44

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/2518749/convert-sequence-of-system-windows-forms-keys-to-a-char

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!