diff options
Diffstat (limited to 'platform/android/android_keys_utils.cpp')
-rw-r--r-- | platform/android/android_keys_utils.cpp | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/platform/android/android_keys_utils.cpp b/platform/android/android_keys_utils.cpp index 885e4ff145..d2c5fdfd6c 100644 --- a/platform/android/android_keys_utils.cpp +++ b/platform/android/android_keys_utils.cpp @@ -30,12 +30,49 @@ #include "android_keys_utils.h" -Key android_get_keysym(unsigned int p_code) { - for (int i = 0; _ak_to_keycode[i].keysym != Key::UNKNOWN; i++) { - if (_ak_to_keycode[i].keycode == p_code) { - return _ak_to_keycode[i].keysym; +Key godot_code_from_android_code(unsigned int p_code) { + for (int i = 0; android_godot_code_pairs[i].android_code != AKEYCODE_MAX; i++) { + if (android_godot_code_pairs[i].android_code == p_code) { + return android_godot_code_pairs[i].godot_code; } } - return Key::UNKNOWN; } + +Key godot_code_from_unicode(unsigned int p_code) { + unsigned int code = p_code; + if (code > 0xFF) { + return Key::UNKNOWN; + } + // Known control codes. + if (code == '\b') { // 0x08 + return Key::BACKSPACE; + } + if (code == '\t') { // 0x09 + return Key::TAB; + } + if (code == '\n') { // 0x0A + return Key::ENTER; + } + if (code == 0x1B) { + return Key::ESCAPE; + } + if (code == 0x1F) { + return Key::KEY_DELETE; + } + // Unknown control codes. + if (code <= 0x1F || (code >= 0x80 && code <= 0x9F)) { + return Key::UNKNOWN; + } + // Convert to uppercase. + if (code >= 'a' && code <= 'z') { // 0x61 - 0x7A + code -= ('a' - 'A'); + } + if (code >= u'à' && code <= u'ö') { // 0xE0 - 0xF6 + code -= (u'à' - u'À'); // 0xE0 - 0xC0 + } + if (code >= u'ø' && code <= u'þ') { // 0xF8 - 0xFF + code -= (u'ø' - u'Ø'); // 0xF8 - 0xD8 + } + return Key(code); +} |