I'm having trouble simulating character clicks when Windows uses a non-English input language.
I tried calling SendInput () with KEYEVENTF_UNICODE:
KEYBDINPUT ki; INPUT input; int character = 0; ki.wVk = 0; ki.wScan = character; ki.dwFlags = KEYEVENTF_UNICODE; ki.time = 0; ki.dwExtraInfo = 0; input.type = INPUT_KEYBOARD; input.ki = ki; SendInput(1, &input, sizeof(INPUT));
And it really works (of course, in my code, I also do KEYUP after pressing the key) ... except for GTK + applications (there may be other instances in which it also does not work).
According to MSDN , if KEYEVENTF_UNICODE is specified, SendInput sends a WM_KEYDOWN or WM_KEYUP message to the foreground thread message queue with wParam equal to VK_PACKET. When GetMessage or PeekMessage receives this message, sending the message to TranslateMessage sends a WM_CHAR message with the Unicode character originally specified by wScan. This Unicode character will be automatically converted to the corresponding ANSI value if it is sent to the ANSI window.
Therefore, I believe that when KEYEVENTF_UNICODE is passed, the functionality of SendInput () is different ... not as low as usual.
Throughout my life, I cannot find another way to get SendInput () to correctly print characters for the user's keyboard language. For example, if the input language on the keyboard is "Swedish", I cannot force it to display "@" (instead it prints a quotation mark), and I cannot force it to output characters other than ASCII, either (letters with an accent, etc. .).
Thanks in advance.
source share