Cleanup and unify keyboard input.

- Unify keycode values (secondary label printed on a key), remove unused hardcoded Latin-1 codes.
- Unify IME behaviour, add inline composition string display on Windows and X11.
- Add key_label (localized label printed on a key) value to the key events, and allow mapping actions to the unshifted Unicode events.
- Add support for physical keyboard (Bluetooth or Sidecar) handling on iOS.
- Add support for media key handling on macOS.

Co-authored-by: Raul Santos <raulsntos@gmail.com>
This commit is contained in:
bruvzg
2022-12-11 01:21:22 +02:00
parent 9937915ad7
commit daad4aed62
61 changed files with 4464 additions and 3655 deletions

View File

@@ -121,18 +121,25 @@ void DisplayServerWeb::key_callback(int p_pressed, int p_repeat, int p_modifiers
// Resume audio context after input in case autoplay was denied.
OS_Web::get_singleton()->resume_audio();
char32_t c = 0x00;
String unicode = String::utf8(key_event.key);
if (unicode.length() == 1) {
c = unicode[0];
}
Key keycode = dom_code2godot_scancode(key_event.code, key_event.key, false);
Key scancode = dom_code2godot_scancode(key_event.code, key_event.key, true);
Ref<InputEventKey> ev;
ev.instantiate();
ev->set_echo(p_repeat);
ev->set_keycode(dom_code2godot_scancode(key_event.code, key_event.key, false));
ev->set_physical_keycode(dom_code2godot_scancode(key_event.code, key_event.key, true));
ev->set_keycode(fix_keycode(c, keycode));
ev->set_physical_keycode(scancode);
ev->set_key_label(fix_key_label(c, keycode));
ev->set_unicode(fix_unicode(c));
ev->set_pressed(p_pressed);
dom2godot_mod(ev, p_modifiers);
String unicode = String::utf8(key_event.key);
if (unicode.length() == 1) {
ev->set_unicode(unicode[0]);
}
Input::get_singleton()->parse_input_event(ev);
// Make sure to flush all events so we can call restricted APIs inside the event.