| 67 | } |
| 68 | |
| 69 | void AndroidInputHandler::process_key_event(int p_physical_keycode, int p_unicode, int p_key_label, bool p_pressed, bool p_echo) { |
| 70 | static char32_t prev_wc = 0; |
| 71 | char32_t unicode = p_unicode; |
| 72 | if ((p_unicode & 0xfffffc00) == 0xd800) { |
| 73 | if (prev_wc != 0) { |
| 74 | ERR_PRINT("invalid utf16 surrogate input"); |
| 75 | } |
| 76 | prev_wc = unicode; |
| 77 | return; // Skip surrogate. |
| 78 | } else if ((unicode & 0xfffffc00) == 0xdc00) { |
| 79 | if (prev_wc == 0) { |
| 80 | ERR_PRINT("invalid utf16 surrogate input"); |
| 81 | return; // Skip invalid surrogate. |
| 82 | } |
| 83 | unicode = (prev_wc << 10UL) + unicode - ((0xd800 << 10UL) + 0xdc00 - 0x10000); |
| 84 | prev_wc = 0; |
| 85 | } else { |
| 86 | prev_wc = 0; |
| 87 | } |
| 88 | |
| 89 | Ref<InputEventKey> ev; |
| 90 | ev.instantiate(); |
| 91 | |
| 92 | Key physical_keycode = godot_code_from_android_code(p_physical_keycode); |
| 93 | Key keycode; |
| 94 | if (unicode == '\b') { // 0x08 |
| 95 | keycode = Key::BACKSPACE; |
| 96 | } else if (unicode == '\t') { // 0x09 |
| 97 | keycode = Key::TAB; |
| 98 | } else if (unicode == '\n') { // 0x0A |
| 99 | keycode = Key::ENTER; |
| 100 | } else if (unicode == 0x1B) { |
| 101 | keycode = Key::ESCAPE; |
| 102 | } else if (unicode == 0x1F) { |
| 103 | keycode = Key::KEY_DELETE; |
| 104 | } else { |
| 105 | keycode = fix_keycode(unicode, physical_keycode); |
| 106 | } |
| 107 | |
| 108 | switch (physical_keycode) { |
| 109 | case Key::SHIFT: { |
| 110 | shift_mem = p_pressed; |
| 111 | } break; |
| 112 | case Key::ALT: { |
| 113 | alt_mem = p_pressed; |
| 114 | } break; |
| 115 | case Key::CTRL: { |
| 116 | control_mem = p_pressed; |
| 117 | } break; |
| 118 | case Key::META: { |
| 119 | meta_mem = p_pressed; |
| 120 | } break; |
| 121 | default: |
| 122 | break; |
| 123 | } |
| 124 | |
| 125 | ev->set_keycode(keycode); |
| 126 | ev->set_physical_keycode(physical_keycode); |
no test coverage detected