2

I have been trying to use the SendInput() function to simulate keyboard input with Unicode characters larger than 2 bytes. I can send characters like ∇ : 0x2207 using the INPUT structure:

INPUT puts[1] = { }; puts[0].type = INPUT_KEYBOARD; puts[0].ki.dwFlags = KEYEVENTF_UNICODE; puts[0].ki.wScan = 0x2207; SendInput(1, puts, sizeof(puts)); 

However when I try to send something like 0x1D495, my character gets truncated to 0xD495 since the wScan member of the KEYBDINPUT (INPUT.ki) is just of type WORD which is only 2 bytes.

I am not experienced with Win32 API, but I have tried bypassing the SendInput() function at my own risk by using SendMessage(), but I am not confident in going about it that way without more formal knowledge. I have tried finding source code for SendInput() to see if I could do more without it, but I didn't find much.

This thread How to use extended scancodes in SendInput addresses the same question, but I was unable to solve my problem since I am not sure what the implied values of tscancode, tvk, and dwFlags would be. Some combination of KEYEVENTF_EXTENDEDKEY, but I couldn't pick apart much.

6
  • 1
    converting your character to utf-16 is likely part of the solution Commented Jul 2, 2024 at 7:22
  • Last time I checked Windows did not support Unicode characters larger than two bytes, i.e. it supports UCS-2 not UTF-16. Commented Jul 2, 2024 at 7:40
  • Possible dupe though this is about the console not SendInput. I wouldn't be surprised to find SendInput has similar limitations. Commented Jul 2, 2024 at 7:43
  • 2
    @john that must have been a long time ago, because Windows has been using UTF-16 for over 2 decades now, since Windows 2000. Commented Jul 2, 2024 at 7:45
  • 1
    @benwu93 the easiest way to handle this is to use KEYEVENTF_UNICODE to send UTF-16 codeunits instead of virtual/extended key codes. I closed your question as a dupe of another question which shows how to do this. Commented Jul 2, 2024 at 7:51

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.