summaryrefslogtreecommitdiff
path: root/platform/web/display_server_web.cpp
diff options
context:
space:
mode:
authorbruvzg <7645683+bruvzg@users.noreply.github.com>2022-12-11 01:21:22 +0200
committerbruvzg <7645683+bruvzg@users.noreply.github.com>2023-01-23 15:08:12 +0200
commitdaad4aed62bfa471421f960179f0ac0fd78e8040 (patch)
tree86b7f69d180f253c51c4b567139d68850f9e365d /platform/web/display_server_web.cpp
parent9937915ad77059b63582ffd4e324afb26f467b76 (diff)
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>
Diffstat (limited to 'platform/web/display_server_web.cpp')
-rw-r--r--platform/web/display_server_web.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/platform/web/display_server_web.cpp b/platform/web/display_server_web.cpp
index fdb9d107a7..d71fd60543 100644
--- a/platform/web/display_server_web.cpp
+++ b/platform/web/display_server_web.cpp
@@ -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.