SendInput() and non-English characters and keyboard layouts

心不动则不痛 提交于 2019-12-05 12:43:51

I discovered that the proper way to do this is to get the virtual-key code of the character by calling VkKeyScanEx() with the character. The high-order bytes of the return value will tell you which modifier keys you need to "press": Control, Alt, and/or Shift; the low-order bytes are the actual virtual-key code.

To get the scan code of the VK, call MapVirtualKeyEx(vkCode, 0);

Then it's just a matter of doing the keypress simulation with the information just obtained.

As I understand it SendInput() is just a wrapper around calls to mouse_event() and keybd_event() that gurantees that your input doesn't get interspersed with input from the user or other callers.

So I guess the question I have is, have you tried using keybd_event()?

Rolf Keller

In .NET all strings are kept as Unicode (UTF-8) strings, internally. You can verify that by converting a string to an array (byte[], NOT char[]!). So you can just ignore anything about scan codes, keyboard layouts and virtual keycodes.

The following works for me in C#/.NET:

string myText = "greekcyrillicjapaneseorwhathaveyou"; // can be input via a Forms textbox

char[] Mychars = myText.ToCharArray();

UInt16 uniCode = chars[5]; // if you want to simulate, say, the sixth' char of the string

...

ki.wScan = unicode

ki.dwFlags = KEYEVENTF_UNICODE;

...

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