[HTML5] Add support for physical_keycode
.
This uses the `event.code` value to retrieve the physical code, while still using the extra logic to map the unicode value to our keylist, when computing the `scancode` (supporting ASCII and Latin-1).
This commit is contained in:
parent
dab4cf3ed6
commit
8740e95f15
2 changed files with 23 additions and 21 deletions
|
@ -31,7 +31,7 @@
|
|||
#include "core/os/keyboard.h"
|
||||
|
||||
// See https://w3c.github.io/uievents-code/#code-value-tables
|
||||
int dom_code2godot_scancode(EM_UTF8 const p_code[32], EM_UTF8 const p_key[32]) {
|
||||
int dom_code2godot_scancode(EM_UTF8 const p_code[32], EM_UTF8 const p_key[32], bool p_physical) {
|
||||
#define DOM2GODOT(p_str, p_godot_code) \
|
||||
if (memcmp((const void *)p_str, (void *)p_code, strlen(p_str) + 1) == 0) { \
|
||||
return KEY_##p_godot_code; \
|
||||
|
@ -71,6 +71,7 @@ int dom_code2godot_scancode(EM_UTF8 const p_code[32], EM_UTF8 const p_key[32]) {
|
|||
DOM2GODOT("NumpadSubtract", KP_SUBTRACT);
|
||||
|
||||
// Printable ASCII.
|
||||
if (!p_physical) {
|
||||
uint8_t b0 = (uint8_t)p_key[0];
|
||||
uint8_t b1 = (uint8_t)p_key[1];
|
||||
uint8_t b2 = (uint8_t)p_key[2];
|
||||
|
@ -96,6 +97,7 @@ int dom_code2godot_scancode(EM_UTF8 const p_code[32], EM_UTF8 const p_key[32]) {
|
|||
}
|
||||
#undef _U_2BYTES_MASK
|
||||
#undef _U_2BYTES
|
||||
}
|
||||
|
||||
// Alphanumeric section.
|
||||
DOM2GODOT("Backquote", QUOTELEFT);
|
||||
|
|
|
@ -240,8 +240,8 @@ static Ref<InputEventKey> setup_key_event(const EmscriptenKeyboardEvent *emscrip
|
|||
ev.instance();
|
||||
ev->set_echo(emscripten_event->repeat);
|
||||
dom2godot_mod(emscripten_event, ev);
|
||||
ev->set_scancode(dom_code2godot_scancode(emscripten_event->code, emscripten_event->key));
|
||||
ev->set_physical_scancode(dom_code2godot_scancode(emscripten_event->code, emscripten_event->key));
|
||||
ev->set_scancode(dom_code2godot_scancode(emscripten_event->code, emscripten_event->key, false));
|
||||
ev->set_physical_scancode(dom_code2godot_scancode(emscripten_event->code, emscripten_event->key, true));
|
||||
|
||||
String unicode = String::utf8(emscripten_event->key);
|
||||
// Check if empty or multi-character (e.g. `CapsLock`).
|
||||
|
|
Loading…
Reference in a new issue