-3

I have a c++ console program. Ho can I simulate the "é" character ? Code:

// Set up a generic keyboard event.
ip.type = INPUT_KEYBOARD;
ip.ki.wScan = 0; // hardware scan code for key
ip.ki.time = 0;
ip.ki.dwExtraInfo = 0; 
ip.ki.wVk = 0x45; //e
ip.ki.dwFlags = 0;
SendInput(1, &ip, sizeof(INPUT));
ip.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &ip, sizeof(INPUT));

How do I convert it to the "é" instead of "e"?

Thanks.

T Jayceon
  • 11
  • 4

1 Answers1

0

Per the KEYBDINPUT documentation, you can use the KEYEVENTF_UNICODE flag:

INPUT ip[2];
// Set up a generic keyboard event.
ip[0].type = INPUT_KEYBOARD;
ip[0].ki.dwFlags = KEYEVENTF_UNICODE;  // We want to send a Unicode key code.
ip[0].ki.wScan = 0x00E9;               // Unicode value of é
ip[0].ki.time = 0;
ip[0].ki.dwExtraInfo = 0; 
ip[0].ki.wVk = 0;                      // Ignored

ip[1] = ip[0];  // Duplicate entry
ip[1].ki.dwFlags |= KEYEVENTF_KEYUP;  // but make it key up

SendInput( 2, ip, sizeof(ip[0]));

(If you are ambitious, you can make that final "2" be your favourite ARRAY_COUNT macro or template function.)

  • Even when using `KEYEVENTF_UNICODE`, you still need to send two input events, one without `KEYEVENTF_KEYUP` and one with. And note that `wScan` is expressed in UTF-16, so if you need to send a Unicode character that uses a surrogate pair, you need separate input events for each surrogate. – Remy Lebeau Aug 03 '16 at 16:20
  • @RemyLebeau: Are you sure? The documentation says that " This flag `KEYEVENTF_UNICODE` can only be combined with the `KEYEVENTF_KEYUP` flag." – Martin Bonner supports Monica Aug 03 '16 at 20:22
  • 1
    Oh, I think I see. It cannot be *combined* with another flag, but it can be used on it's own. I'll edit the code. – Martin Bonner supports Monica Aug 03 '16 at 20:23