Add support for Unicode input messages on Windows

This commit is contained in:
Cameron Gutman
2022-11-22 19:17:53 -06:00
parent d912cce5ba
commit e39d9bc662
5 changed files with 56 additions and 0 deletions

View File

@@ -296,6 +296,7 @@ void button_mouse(input_t &input, int button, bool release);
void scroll(input_t &input, int distance);
void keyboard(input_t &input, uint16_t modcode, bool release);
void gamepad(input_t &input, int nr, const gamepad_state_t &gamepad_state);
void unicode(input_t &input, char *utf8, int size);
int alloc_gamepad(input_t &input, int nr, rumble_queue_t rumble_queue);
void free_gamepad(input_t &input, int nr);

View File

@@ -994,6 +994,10 @@ void keyboard(input_t &input, uint16_t modcode, bool release) {
keycode.pressed = 1;
}
void unicode(input_t &input, char *utf8, int size) {
BOOST_LOG(info) << "unicode: Unicode input not yet implemented for Linux."sv;
}
int alloc_gamepad(input_t &input, int nr, rumble_queue_t rumble_queue) {
return ((input_raw_t *)input.get())->alloc_gamepad(nr, std::move(rumble_queue));
}

View File

@@ -277,6 +277,10 @@ void keyboard(input_t &input, uint16_t modcode, bool release) {
CGEventPost(kCGHIDEventTap, event);
}
void unicode(input_t &input, char *utf8, int size) {
BOOST_LOG(info) << "unicode: Unicode input not yet implemented for MacOS."sv;
}
int alloc_gamepad(input_t &input, int nr, rumble_queue_t rumble_queue) {
BOOST_LOG(info) << "alloc_gamepad: Gamepad not yet implemented for MacOS."sv;
return -1;

View File

@@ -326,6 +326,34 @@ void keyboard(input_t &input, uint16_t modcode, bool release) {
send_input(i);
}
void unicode(input_t &input, char *utf8, int size) {
// We can do no worse than one UTF-16 character per byte of UTF-8
WCHAR wide[size];
int chars = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, utf8, size, wide, size);
if(chars <= 0) {
return;
}
// Send all key down events
for(int i = 0; i < chars; i++) {
INPUT input {};
input.type = INPUT_KEYBOARD;
input.ki.wScan = wide[i];
input.ki.dwFlags = KEYEVENTF_UNICODE;
send_input(input);
}
// Send all key up events
for(int i = 0; i < chars; i++) {
INPUT input {};
input.type = INPUT_KEYBOARD;
input.ki.wScan = wide[i];
input.ki.dwFlags = KEYEVENTF_UNICODE | KEYEVENTF_KEYUP;
send_input(input);
}
}
int alloc_gamepad(input_t &input, int nr, rumble_queue_t rumble_queue) {
if(!input) {
return 0;