I have a utf-8 formatted file that contains a character 'ů
', when I read it in c++ using ifstream and cout it, the output is 'ů
'. I can solve it by adding 'SetConsoleOutputCP( 65001 );
', afterwards Im sending the char using 'SendInput();
' to another window. But because the SetConsoleOutput() doesnt affect SendInput() the application recieves the corrupted character 'ů
'.
The question is how to SendInput() accented character?
ifstream file(path);
string str;
while (getline (file, str))
{
cout << endl << str <<endl;
for (char &c : str) {
INPUT ip;
ip.type = INPUT_KEYBOARD;
ip.ki.wScan = 0;
ip.ki.time = 0;
ip.ki.dwExtraInfo = 0;
ip.ki.dwFlags = KEYEVENTF_UNICODE;
if (isupper(c)) {
ip.ki.wVk = VK_LSHIFT;
SendInput(1, &ip, sizeof(INPUT));
} else {
ip.ki.dwFlags = KEYEVENTF_KEYUP;
ip.ki.wVk = VK_LSHIFT;
SendInput(1, &ip, sizeof(INPUT));
ip.ki.dwFlags = KEYEVENTF_UNICODE;
}
ip.ki.wVk = VkKeyScanA(c);
SendInput(1, &ip, sizeof(INPUT));
Sleep(100);
}
INPUT enter;
enter.type = INPUT_KEYBOARD;
enter.ki.wScan = 0;
enter.ki.time = 0;
enter.ki.dwExtraInfo = 0;
enter.ki.dwFlags = 0;
enter.ki.wVk = VK_RETURN;
SendInput(1, &enter, sizeof(INPUT));
cout << "enter pressed";
}