diff options
Diffstat (limited to 'platform/macos')
-rw-r--r-- | platform/macos/detect.py | 2 | ||||
-rw-r--r-- | platform/macos/display_server_macos.h | 5 | ||||
-rw-r--r-- | platform/macos/display_server_macos.mm | 26 | ||||
-rw-r--r-- | platform/macos/export/export_plugin.cpp | 4 | ||||
-rw-r--r-- | platform/macos/godot_application.h | 1 | ||||
-rw-r--r-- | platform/macos/godot_application.mm | 74 | ||||
-rw-r--r-- | platform/macos/godot_content_view.h | 1 | ||||
-rw-r--r-- | platform/macos/godot_content_view.mm | 164 | ||||
-rw-r--r-- | platform/macos/key_mapping_macos.h | 10 | ||||
-rw-r--r-- | platform/macos/key_mapping_macos.mm | 717 |
10 files changed, 502 insertions, 502 deletions
diff --git a/platform/macos/detect.py b/platform/macos/detect.py index 14e6e92bfa..cd46dab4f3 100644 --- a/platform/macos/detect.py +++ b/platform/macos/detect.py @@ -230,7 +230,7 @@ def configure(env: "Environment"): env.Append(LIBS=["pthread", "z"]) if env["opengl3"]: - env.Append(CPPDEFINES=["GLES_ENABLED", "GLES3_ENABLED"]) + env.Append(CPPDEFINES=["GLES3_ENABLED"]) env.Append(LINKFLAGS=["-framework", "OpenGL"]) env.Append(LINKFLAGS=["-rpath", "@executable_path/../Frameworks", "-rpath", "@executable_path"]) diff --git a/platform/macos/display_server_macos.h b/platform/macos/display_server_macos.h index 4873db4b64..fb9bcdfe56 100644 --- a/platform/macos/display_server_macos.h +++ b/platform/macos/display_server_macos.h @@ -69,6 +69,7 @@ public: bool raw = false; Key keycode = Key::NONE; Key physical_keycode = Key::NONE; + Key key_label = Key::NONE; uint32_t unicode = 0; }; @@ -201,8 +202,6 @@ private: Point2i _get_native_screen_position(int p_screen) const; static void _displays_arrangement_changed(CGDirectDisplayID display_id, CGDisplayChangeSummaryFlags flags, void *user_info); - WindowID _get_focused_window_or_popup() const; - static void _dispatch_input_events(const Ref<InputEvent> &p_event); void _dispatch_input_event(const Ref<InputEvent> &p_event); void _push_input(const Ref<InputEvent> &p_event); @@ -229,6 +228,7 @@ public: void get_key_modifier_state(unsigned int p_macos_state, Ref<InputEventWithModifiers> r_state) const; void update_mouse_pos(WindowData &p_wd, NSPoint p_location_in_window); void push_to_key_event_buffer(const KeyEvent &p_event); + void pop_last_key_event(); void update_im_text(const Point2i &p_selection, const String &p_text); void set_last_focused_window(WindowID p_window); bool mouse_process_popups(bool p_close = false); @@ -237,6 +237,7 @@ public: void set_is_resizing(bool p_is_resizing); bool get_is_resizing() const; void reparent_check(WindowID p_window); + WindowID _get_focused_window_or_popup() const; void window_update(WindowID p_window); void window_destroy(WindowID p_window); diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm index d992467042..2832495693 100644 --- a/platform/macos/display_server_macos.mm +++ b/platform/macos/display_server_macos.mm @@ -434,7 +434,8 @@ void DisplayServerMacOS::_process_key_events() { k->set_pressed(ke.pressed); k->set_echo(ke.echo); k->set_keycode(ke.keycode); - k->set_physical_keycode((Key)ke.physical_keycode); + k->set_physical_keycode(ke.physical_keycode); + k->set_key_label(ke.key_label); k->set_unicode(ke.unicode); _push_input(k); @@ -449,6 +450,7 @@ void DisplayServerMacOS::_process_key_events() { k->set_echo(ke.echo); k->set_keycode(Key::NONE); k->set_physical_keycode(Key::NONE); + k->set_key_label(Key::NONE); k->set_unicode(ke.unicode); _push_input(k); @@ -461,7 +463,8 @@ void DisplayServerMacOS::_process_key_events() { k->set_pressed(ke.pressed); k->set_echo(ke.echo); k->set_keycode(ke.keycode); - k->set_physical_keycode((Key)ke.physical_keycode); + k->set_physical_keycode(ke.physical_keycode); + k->set_key_label(ke.key_label); if (i + 1 < key_event_pos && key_event_buffer[i + 1].keycode == Key::NONE) { k->set_unicode(key_event_buffer[i + 1].unicode); @@ -633,6 +636,7 @@ void DisplayServerMacOS::send_event(NSEvent *p_event) { k->set_pressed(true); k->set_keycode(Key::PERIOD); k->set_physical_keycode(Key::PERIOD); + k->set_key_label(Key::PERIOD); k->set_echo([p_event isARepeat]); Input::get_singleton()->parse_input_event(k); @@ -674,6 +678,12 @@ void DisplayServerMacOS::update_mouse_pos(DisplayServerMacOS::WindowData &p_wd, Input::get_singleton()->set_mouse_position(p_wd.mouse_pos); } +void DisplayServerMacOS::pop_last_key_event() { + if (key_event_pos > 0) { + key_event_pos--; + } +} + void DisplayServerMacOS::push_to_key_event_buffer(const DisplayServerMacOS::KeyEvent &p_event) { if (key_event_pos >= key_event_buffer.size()) { key_event_buffer.resize(1 + key_event_pos); @@ -3142,7 +3152,9 @@ ObjectID DisplayServerMacOS::window_get_attached_instance_id(WindowID p_window) void DisplayServerMacOS::gl_window_make_current(DisplayServer::WindowID p_window_id) { #if defined(GLES3_ENABLED) - gl_manager->window_make_current(p_window_id); + if (gl_manager) { + gl_manager->window_make_current(p_window_id); + } #endif } @@ -3449,14 +3461,14 @@ String DisplayServerMacOS::keyboard_get_layout_name(int p_index) const { } Key DisplayServerMacOS::keyboard_get_keycode_from_physical(Key p_keycode) const { - if (p_keycode == Key::PAUSE) { + if (p_keycode == Key::PAUSE || p_keycode == Key::NONE) { return p_keycode; } Key modifiers = p_keycode & KeyModifierMask::MODIFIER_MASK; Key keycode_no_mod = p_keycode & KeyModifierMask::CODE_MASK; - unsigned int macos_keycode = KeyMappingMacOS::unmap_key((Key)keycode_no_mod); - return (Key)(KeyMappingMacOS::remap_key(macos_keycode, 0) | modifiers); + unsigned int macos_keycode = KeyMappingMacOS::unmap_key(keycode_no_mod); + return (Key)(KeyMappingMacOS::remap_key(macos_keycode, 0, false) | modifiers); } void DisplayServerMacOS::process_events() { @@ -3768,6 +3780,8 @@ bool DisplayServerMacOS::mouse_process_popups(bool p_close) { } DisplayServerMacOS::DisplayServerMacOS(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Error &r_error) { + KeyMappingMacOS::initialize(); + Input::get_singleton()->set_event_dispatch_function(_dispatch_input_events); r_error = OK; diff --git a/platform/macos/export/export_plugin.cpp b/platform/macos/export/export_plugin.cpp index 73fbd45400..5c20016aa5 100644 --- a/platform/macos/export/export_plugin.cpp +++ b/platform/macos/export/export_plugin.cpp @@ -2016,8 +2016,8 @@ Error EditorExportPlatformMacOS::run(const Ref<EditorExportPreset> &p_preset, in if (port.is_empty()) { port = "22"; } - Vector<String> extra_args_ssh = p_preset->get("ssh_remote_deploy/extra_args_ssh").operator String().split(" "); - Vector<String> extra_args_scp = p_preset->get("ssh_remote_deploy/extra_args_scp").operator String().split(" "); + Vector<String> extra_args_ssh = p_preset->get("ssh_remote_deploy/extra_args_ssh").operator String().split(" ", false); + Vector<String> extra_args_scp = p_preset->get("ssh_remote_deploy/extra_args_scp").operator String().split(" ", false); const String basepath = dest.path_join("tmp_macos_export"); diff --git a/platform/macos/godot_application.h b/platform/macos/godot_application.h index f41fc2646d..8749c8fbb0 100644 --- a/platform/macos/godot_application.h +++ b/platform/macos/godot_application.h @@ -35,6 +35,7 @@ #import <AppKit/AppKit.h> #import <Foundation/Foundation.h> +#import <IOKit/hidsystem/ev_keymap.h> @interface GodotApplication : NSApplication @end diff --git a/platform/macos/godot_application.mm b/platform/macos/godot_application.mm index 0c282930f4..e3a744caa2 100644 --- a/platform/macos/godot_application.mm +++ b/platform/macos/godot_application.mm @@ -34,7 +34,81 @@ @implementation GodotApplication +- (void)mediaKeyEvent:(int)key state:(BOOL)state repeat:(BOOL)repeat { + Key keycode = Key::NONE; + switch (key) { + case NX_KEYTYPE_SOUND_UP: { + keycode = Key::VOLUMEUP; + } break; + case NX_KEYTYPE_SOUND_DOWN: { + keycode = Key::VOLUMEUP; + } break; + //NX_KEYTYPE_BRIGHTNESS_UP + //NX_KEYTYPE_BRIGHTNESS_DOWN + case NX_KEYTYPE_CAPS_LOCK: { + keycode = Key::CAPSLOCK; + } break; + case NX_KEYTYPE_HELP: { + keycode = Key::HELP; + } break; + case NX_POWER_KEY: { + keycode = Key::STANDBY; + } break; + case NX_KEYTYPE_MUTE: { + keycode = Key::VOLUMEMUTE; + } break; + //NX_KEYTYPE_CONTRAST_UP + //NX_KEYTYPE_CONTRAST_DOWN + //NX_KEYTYPE_LAUNCH_PANEL + //NX_KEYTYPE_EJECT + //NX_KEYTYPE_VIDMIRROR + //NX_KEYTYPE_FAST + //NX_KEYTYPE_REWIND + //NX_KEYTYPE_ILLUMINATION_UP + //NX_KEYTYPE_ILLUMINATION_DOWN + //NX_KEYTYPE_ILLUMINATION_TOGGLE + case NX_KEYTYPE_PLAY: { + keycode = Key::MEDIAPLAY; + } break; + case NX_KEYTYPE_NEXT: { + keycode = Key::MEDIANEXT; + } break; + case NX_KEYTYPE_PREVIOUS: { + keycode = Key::MEDIAPREVIOUS; + } break; + default: { + keycode = Key::NONE; + } break; + } + + DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton(); + if (ds && keycode != Key::NONE) { + DisplayServerMacOS::KeyEvent ke; + + ke.window_id = ds->_get_focused_window_or_popup(); + ke.macos_state = 0; + ke.pressed = state; + ke.echo = repeat; + ke.keycode = keycode; + ke.physical_keycode = keycode; + ke.key_label = keycode; + ke.unicode = 0; + ke.raw = true; + + ds->push_to_key_event_buffer(ke); + } +} + - (void)sendEvent:(NSEvent *)event { + if ([event type] == NSSystemDefined && [event subtype] == 8) { + int keyCode = (([event data1] & 0xFFFF0000) >> 16); + int keyFlags = ([event data1] & 0x0000FFFF); + int keyState = (((keyFlags & 0xFF00) >> 8)) == 0xA; + int keyRepeat = (keyFlags & 0x1); + + [self mediaKeyEvent:keyCode state:keyState repeat:keyRepeat]; + } + DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton(); if (ds) { if ([event type] == NSEventTypeLeftMouseDown || [event type] == NSEventTypeRightMouseDown || [event type] == NSEventTypeOtherMouseDown) { diff --git a/platform/macos/godot_content_view.h b/platform/macos/godot_content_view.h index e660285e49..0d18ac742a 100644 --- a/platform/macos/godot_content_view.h +++ b/platform/macos/godot_content_view.h @@ -64,6 +64,7 @@ bool mouse_down_control; bool ignore_momentum_scroll; bool last_pen_inverted; + bool ime_suppress_next_keyup; id layer_delegate; } diff --git a/platform/macos/godot_content_view.mm b/platform/macos/godot_content_view.mm index 337aa59a5e..485f80a22e 100644 --- a/platform/macos/godot_content_view.mm +++ b/platform/macos/godot_content_view.mm @@ -185,6 +185,7 @@ DisplayServerMacOS::WindowData &wd = ds->get_window(window_id); if (wd.im_active) { ime_input_event_in_progress = true; + ds->pop_last_key_event(); ds->update_im_text(Point2i(selectedRange.location, selectedRange.length), String::utf8([[marked_text mutableString] UTF8String])); } } @@ -194,6 +195,9 @@ } - (void)unmarkText { + if (ime_input_event_in_progress) { + ime_suppress_next_keyup = true; + } ime_input_event_in_progress = false; [[marked_text mutableString] setString:@""]; @@ -245,8 +249,6 @@ } - (void)insertText:(id)aString replacementRange:(NSRange)replacementRange { - NSEvent *event = [NSApp currentEvent]; - NSString *characters; if ([aString isKindOfClass:[NSAttributedString class]]) { characters = [aString string]; @@ -284,13 +286,14 @@ DisplayServerMacOS::KeyEvent ke; ke.window_id = window_id; - ke.macos_state = [event modifierFlags]; + ke.macos_state = 0; ke.pressed = true; ke.echo = false; ke.raw = false; // IME input event. ke.keycode = Key::NONE; ke.physical_keycode = Key::NONE; - ke.unicode = codepoint; + ke.key_label = Key::NONE; + ke.unicode = fix_unicode(codepoint); ds->push_to_key_event_buffer(ke); } @@ -584,7 +587,7 @@ NSString *characters = [event characters]; NSUInteger length = [characters length]; - if (!wd.im_active && length > 0 && keycode_has_unicode(KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags]))) { + if (!wd.im_active && length > 0 && keycode_has_unicode(KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags], true))) { // Fallback unicode character handler used if IME is not active. Char16String text; text.resize([characters length] + 1); @@ -602,10 +605,11 @@ ke.macos_state = [event modifierFlags]; ke.pressed = true; ke.echo = [event isARepeat]; - ke.keycode = KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags]); + ke.keycode = KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags], false); ke.physical_keycode = KeyMappingMacOS::translate_key([event keyCode]); + ke.key_label = KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags], true); + ke.unicode = fix_unicode(codepoint); ke.raw = true; - ke.unicode = codepoint; ds->push_to_key_event_buffer(ke); } @@ -616,10 +620,11 @@ ke.macos_state = [event modifierFlags]; ke.pressed = true; ke.echo = [event isARepeat]; - ke.keycode = KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags]); + ke.keycode = KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags], false); ke.physical_keycode = KeyMappingMacOS::translate_key([event keyCode]); - ke.raw = false; + ke.key_label = KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags], true); ke.unicode = 0; + ke.raw = false; ds->push_to_key_event_buffer(ke); } @@ -638,56 +643,54 @@ } ignore_momentum_scroll = true; - // Ignore all input if IME input is in progress - if (!ime_input_event_in_progress) { - DisplayServerMacOS::KeyEvent ke; + DisplayServerMacOS::KeyEvent ke; - ke.window_id = window_id; - ke.echo = false; - ke.raw = true; + ke.window_id = window_id; + ke.echo = false; + ke.raw = true; - int key = [event keyCode]; - int mod = [event modifierFlags]; + int key = [event keyCode]; + int mod = [event modifierFlags]; - if (key == 0x36 || key == 0x37) { - if (mod & NSEventModifierFlagCommand) { - mod &= ~NSEventModifierFlagCommand; - ke.pressed = true; - } else { - ke.pressed = false; - } - } else if (key == 0x38 || key == 0x3c) { - if (mod & NSEventModifierFlagShift) { - mod &= ~NSEventModifierFlagShift; - ke.pressed = true; - } else { - ke.pressed = false; - } - } else if (key == 0x3a || key == 0x3d) { - if (mod & NSEventModifierFlagOption) { - mod &= ~NSEventModifierFlagOption; - ke.pressed = true; - } else { - ke.pressed = false; - } - } else if (key == 0x3b || key == 0x3e) { - if (mod & NSEventModifierFlagControl) { - mod &= ~NSEventModifierFlagControl; - ke.pressed = true; - } else { - ke.pressed = false; - } + if (key == 0x36 || key == 0x37) { + if (mod & NSEventModifierFlagCommand) { + mod &= ~NSEventModifierFlagCommand; + ke.pressed = true; } else { - return; + ke.pressed = false; } + } else if (key == 0x38 || key == 0x3c) { + if (mod & NSEventModifierFlagShift) { + mod &= ~NSEventModifierFlagShift; + ke.pressed = true; + } else { + ke.pressed = false; + } + } else if (key == 0x3a || key == 0x3d) { + if (mod & NSEventModifierFlagOption) { + mod &= ~NSEventModifierFlagOption; + ke.pressed = true; + } else { + ke.pressed = false; + } + } else if (key == 0x3b || key == 0x3e) { + if (mod & NSEventModifierFlagControl) { + mod &= ~NSEventModifierFlagControl; + ke.pressed = true; + } else { + ke.pressed = false; + } + } else { + return; + } - ke.macos_state = mod; - ke.keycode = KeyMappingMacOS::remap_key(key, mod); - ke.physical_keycode = KeyMappingMacOS::translate_key(key); - ke.unicode = 0; + ke.macos_state = mod; + ke.keycode = KeyMappingMacOS::remap_key(key, mod, false); + ke.physical_keycode = KeyMappingMacOS::translate_key(key); + ke.key_label = KeyMappingMacOS::remap_key(key, mod, true); + ke.unicode = 0; - ds->push_to_key_event_buffer(ke); - } + ds->push_to_key_event_buffer(ke); } - (void)keyUp:(NSEvent *)event { @@ -696,51 +699,26 @@ return; } - DisplayServerMacOS::WindowData &wd = ds->get_window(window_id); - // Ignore all input if IME input is in progress. - if (!ime_input_event_in_progress) { - NSString *characters = [event characters]; - NSUInteger length = [characters length]; - - // Fallback unicode character handler used if IME is not active. - if (!wd.im_active && length > 0 && keycode_has_unicode(KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags]))) { - Char16String text; - text.resize([characters length] + 1); - [characters getCharacters:(unichar *)text.ptrw() range:NSMakeRange(0, [characters length])]; - - String u32text; - u32text.parse_utf16(text.ptr(), text.length()); - - for (int i = 0; i < u32text.length(); i++) { - const char32_t codepoint = u32text[i]; - DisplayServerMacOS::KeyEvent ke; - - ke.window_id = window_id; - ke.macos_state = [event modifierFlags]; - ke.pressed = false; - ke.echo = [event isARepeat]; - ke.keycode = KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags]); - ke.physical_keycode = KeyMappingMacOS::translate_key([event keyCode]); - ke.raw = true; - ke.unicode = codepoint; + if (ime_suppress_next_keyup) { + ime_suppress_next_keyup = false; + return; + } - ds->push_to_key_event_buffer(ke); - } - } else { - DisplayServerMacOS::KeyEvent ke; + if (!ime_input_event_in_progress) { + DisplayServerMacOS::KeyEvent ke; - ke.window_id = window_id; - ke.macos_state = [event modifierFlags]; - ke.pressed = false; - ke.echo = [event isARepeat]; - ke.keycode = KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags]); - ke.physical_keycode = KeyMappingMacOS::translate_key([event keyCode]); - ke.raw = true; - ke.unicode = 0; + ke.window_id = window_id; + ke.macos_state = [event modifierFlags]; + ke.pressed = false; + ke.echo = [event isARepeat]; + ke.keycode = KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags], false); + ke.physical_keycode = KeyMappingMacOS::translate_key([event keyCode]); + ke.key_label = KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags], true); + ke.unicode = 0; + ke.raw = true; - ds->push_to_key_event_buffer(ke); - } + ds->push_to_key_event_buffer(ke); } } diff --git a/platform/macos/key_mapping_macos.h b/platform/macos/key_mapping_macos.h index 5128005627..1bda4eb406 100644 --- a/platform/macos/key_mapping_macos.h +++ b/platform/macos/key_mapping_macos.h @@ -36,13 +36,15 @@ class KeyMappingMacOS { KeyMappingMacOS() {} - static bool is_numpad_key(unsigned int key); + static bool is_numpad_key(unsigned int p_key); public: + static void initialize(); + // Mappings input. - static Key translate_key(unsigned int key); - static unsigned int unmap_key(Key key); - static Key remap_key(unsigned int key, unsigned int state); + static Key translate_key(unsigned int p_key); + static unsigned int unmap_key(Key p_key); + static Key remap_key(unsigned int p_key, unsigned int p_state, bool p_unicode); // Mapping for menu shortcuts. static String keycode_get_native_string(Key p_keycode); diff --git a/platform/macos/key_mapping_macos.mm b/platform/macos/key_mapping_macos.mm index 478c84e81c..31b71ac1b8 100644 --- a/platform/macos/key_mapping_macos.mm +++ b/platform/macos/key_mapping_macos.mm @@ -33,277 +33,345 @@ #import <Carbon/Carbon.h> #import <Cocoa/Cocoa.h> -bool KeyMappingMacOS::is_numpad_key(unsigned int key) { - static const unsigned int table[] = { - 0x41, /* kVK_ANSI_KeypadDecimal */ - 0x43, /* kVK_ANSI_KeypadMultiply */ - 0x45, /* kVK_ANSI_KeypadPlus */ - 0x47, /* kVK_ANSI_KeypadClear */ - 0x4b, /* kVK_ANSI_KeypadDivide */ - 0x4c, /* kVK_ANSI_KeypadEnter */ - 0x4e, /* kVK_ANSI_KeypadMinus */ - 0x51, /* kVK_ANSI_KeypadEquals */ - 0x52, /* kVK_ANSI_Keypad0 */ - 0x53, /* kVK_ANSI_Keypad1 */ - 0x54, /* kVK_ANSI_Keypad2 */ - 0x55, /* kVK_ANSI_Keypad3 */ - 0x56, /* kVK_ANSI_Keypad4 */ - 0x57, /* kVK_ANSI_Keypad5 */ - 0x58, /* kVK_ANSI_Keypad6 */ - 0x59, /* kVK_ANSI_Keypad7 */ - 0x5b, /* kVK_ANSI_Keypad8 */ - 0x5c, /* kVK_ANSI_Keypad9 */ - 0x5f, /* kVK_JIS_KeypadComma */ - 0x00 - }; - for (int i = 0; table[i] != 0; i++) { - if (key == table[i]) { - return true; - } +#include "core/templates/hash_map.h" +#include "core/templates/hash_set.h" + +struct HashMapHasherKeys { + static _FORCE_INLINE_ uint32_t hash(const Key p_key) { return hash_fmix32(static_cast<uint32_t>(p_key)); } + static _FORCE_INLINE_ uint32_t hash(const char32_t p_uchar) { return hash_fmix32(p_uchar); } + static _FORCE_INLINE_ uint32_t hash(const unsigned p_key) { return hash_fmix32(p_key); } +}; + +HashSet<unsigned int> numpad_keys; +HashMap<unsigned int, Key, HashMapHasherKeys> keysym_map; +HashMap<Key, unsigned int, HashMapHasherKeys> keysym_map_inv; +HashMap<Key, char32_t, HashMapHasherKeys> keycode_map; + +void KeyMappingMacOS::initialize() { + numpad_keys.insert(0x41); //kVK_ANSI_KeypadDecimal + numpad_keys.insert(0x43); //kVK_ANSI_KeypadMultiply + numpad_keys.insert(0x45); //kVK_ANSI_KeypadPlus + numpad_keys.insert(0x47); //kVK_ANSI_KeypadClear + numpad_keys.insert(0x4b); //kVK_ANSI_KeypadDivide + numpad_keys.insert(0x4c); //kVK_ANSI_KeypadEnter + numpad_keys.insert(0x4e); //kVK_ANSI_KeypadMinus + numpad_keys.insert(0x51); //kVK_ANSI_KeypadEquals + numpad_keys.insert(0x52); //kVK_ANSI_Keypad0 + numpad_keys.insert(0x53); //kVK_ANSI_Keypad1 + numpad_keys.insert(0x54); //kVK_ANSI_Keypad2 + numpad_keys.insert(0x55); //kVK_ANSI_Keypad3 + numpad_keys.insert(0x56); //kVK_ANSI_Keypad4 + numpad_keys.insert(0x57); //kVK_ANSI_Keypad5 + numpad_keys.insert(0x58); //kVK_ANSI_Keypad6 + numpad_keys.insert(0x59); //kVK_ANSI_Keypad7 + numpad_keys.insert(0x5b); //kVK_ANSI_Keypad8 + numpad_keys.insert(0x5c); //kVK_ANSI_Keypad9 + numpad_keys.insert(0x5f); //kVK_JIS_KeypadComma + + keysym_map[0x00] = Key::A; + keysym_map[0x01] = Key::S; + keysym_map[0x02] = Key::D; + keysym_map[0x03] = Key::F; + keysym_map[0x04] = Key::H; + keysym_map[0x05] = Key::G; + keysym_map[0x06] = Key::Z; + keysym_map[0x07] = Key::X; + keysym_map[0x08] = Key::C; + keysym_map[0x09] = Key::V; + keysym_map[0x0a] = Key::SECTION; + keysym_map[0x0b] = Key::B; + keysym_map[0x0c] = Key::Q; + keysym_map[0x0d] = Key::W; + keysym_map[0x0e] = Key::E; + keysym_map[0x0f] = Key::R; + keysym_map[0x10] = Key::Y; + keysym_map[0x11] = Key::T; + keysym_map[0x12] = Key::KEY_1; + keysym_map[0x13] = Key::KEY_2; + keysym_map[0x14] = Key::KEY_3; + keysym_map[0x15] = Key::KEY_4; + keysym_map[0x16] = Key::KEY_6; + keysym_map[0x17] = Key::KEY_5; + keysym_map[0x18] = Key::EQUAL; + keysym_map[0x19] = Key::KEY_9; + keysym_map[0x1a] = Key::KEY_7; + keysym_map[0x1b] = Key::MINUS; + keysym_map[0x1c] = Key::KEY_8; + keysym_map[0x1d] = Key::KEY_0; + keysym_map[0x1e] = Key::BRACERIGHT; + keysym_map[0x1f] = Key::O; + keysym_map[0x20] = Key::U; + keysym_map[0x21] = Key::BRACELEFT; + keysym_map[0x22] = Key::I; + keysym_map[0x23] = Key::P; + keysym_map[0x24] = Key::ENTER; + keysym_map[0x25] = Key::L; + keysym_map[0x26] = Key::J; + keysym_map[0x27] = Key::APOSTROPHE; + keysym_map[0x28] = Key::K; + keysym_map[0x29] = Key::SEMICOLON; + keysym_map[0x2a] = Key::BACKSLASH; + keysym_map[0x2b] = Key::COMMA; + keysym_map[0x2c] = Key::SLASH; + keysym_map[0x2d] = Key::N; + keysym_map[0x2e] = Key::M; + keysym_map[0x2f] = Key::PERIOD; + keysym_map[0x30] = Key::TAB; + keysym_map[0x31] = Key::SPACE; + keysym_map[0x32] = Key::QUOTELEFT; + keysym_map[0x33] = Key::BACKSPACE; + keysym_map[0x35] = Key::ESCAPE; + keysym_map[0x36] = Key::META; + keysym_map[0x37] = Key::META; + keysym_map[0x38] = Key::SHIFT; + keysym_map[0x39] = Key::CAPSLOCK; + keysym_map[0x3a] = Key::ALT; + keysym_map[0x3b] = Key::CTRL; + keysym_map[0x3c] = Key::SHIFT; + keysym_map[0x3d] = Key::ALT; + keysym_map[0x3e] = Key::CTRL; + keysym_map[0x40] = Key::F17; + keysym_map[0x41] = Key::KP_PERIOD; + keysym_map[0x43] = Key::KP_MULTIPLY; + keysym_map[0x45] = Key::KP_ADD; + keysym_map[0x47] = Key::NUMLOCK; + keysym_map[0x48] = Key::VOLUMEUP; + keysym_map[0x49] = Key::VOLUMEDOWN; + keysym_map[0x4a] = Key::VOLUMEMUTE; + keysym_map[0x4b] = Key::KP_DIVIDE; + keysym_map[0x4c] = Key::KP_ENTER; + keysym_map[0x4e] = Key::KP_SUBTRACT; + keysym_map[0x4f] = Key::F18; + keysym_map[0x50] = Key::F19; + keysym_map[0x51] = Key::EQUAL; + keysym_map[0x52] = Key::KP_0; + keysym_map[0x53] = Key::KP_1; + keysym_map[0x54] = Key::KP_2; + keysym_map[0x55] = Key::KP_3; + keysym_map[0x56] = Key::KP_4; + keysym_map[0x57] = Key::KP_5; + keysym_map[0x58] = Key::KP_6; + keysym_map[0x59] = Key::KP_7; + keysym_map[0x5a] = Key::F20; + keysym_map[0x5b] = Key::KP_8; + keysym_map[0x5c] = Key::KP_9; + keysym_map[0x5d] = Key::YEN; + keysym_map[0x5e] = Key::UNDERSCORE; + keysym_map[0x5f] = Key::COMMA; + keysym_map[0x60] = Key::F5; + keysym_map[0x61] = Key::F6; + keysym_map[0x62] = Key::F7; + keysym_map[0x63] = Key::F3; + keysym_map[0x64] = Key::F8; + keysym_map[0x65] = Key::F9; + keysym_map[0x66] = Key::JIS_EISU; + keysym_map[0x67] = Key::F11; + keysym_map[0x68] = Key::JIS_KANA; + keysym_map[0x69] = Key::F13; + keysym_map[0x6a] = Key::F16; + keysym_map[0x6b] = Key::F14; + keysym_map[0x6d] = Key::F10; + keysym_map[0x6e] = Key::MENU; + keysym_map[0x6f] = Key::F12; + keysym_map[0x71] = Key::F15; + keysym_map[0x72] = Key::INSERT; + keysym_map[0x73] = Key::HOME; + keysym_map[0x74] = Key::PAGEUP; + keysym_map[0x75] = Key::KEY_DELETE; + keysym_map[0x76] = Key::F4; + keysym_map[0x77] = Key::END; + keysym_map[0x78] = Key::F2; + keysym_map[0x79] = Key::PAGEDOWN; + keysym_map[0x7a] = Key::F1; + keysym_map[0x7b] = Key::LEFT; + keysym_map[0x7c] = Key::RIGHT; + keysym_map[0x7d] = Key::DOWN; + keysym_map[0x7e] = Key::UP; + + for (const KeyValue<unsigned int, Key> &E : keysym_map) { + keysym_map_inv[E.value] = E.key; } - return false; + + keycode_map[Key::ESCAPE] = 0x001B; + keycode_map[Key::TAB] = 0x0009; + keycode_map[Key::BACKTAB] = 0x007F; + keycode_map[Key::BACKSPACE] = 0x0008; + keycode_map[Key::ENTER] = 0x000D; + keycode_map[Key::INSERT] = NSInsertFunctionKey; + keycode_map[Key::KEY_DELETE] = 0x007F; + keycode_map[Key::PAUSE] = NSPauseFunctionKey; + keycode_map[Key::PRINT] = NSPrintScreenFunctionKey; + keycode_map[Key::SYSREQ] = NSSysReqFunctionKey; + keycode_map[Key::CLEAR] = NSClearLineFunctionKey; + keycode_map[Key::HOME] = 0x2196; + keycode_map[Key::END] = 0x2198; + keycode_map[Key::LEFT] = 0x001C; + keycode_map[Key::UP] = 0x001E; + keycode_map[Key::RIGHT] = 0x001D; + keycode_map[Key::DOWN] = 0x001F; + keycode_map[Key::PAGEUP] = 0x21DE; + keycode_map[Key::PAGEDOWN] = 0x21DF; + keycode_map[Key::NUMLOCK] = NSClearLineFunctionKey; + keycode_map[Key::SCROLLLOCK] = NSScrollLockFunctionKey; + keycode_map[Key::F1] = NSF1FunctionKey; + keycode_map[Key::F2] = NSF2FunctionKey; + keycode_map[Key::F3] = NSF3FunctionKey; + keycode_map[Key::F4] = NSF4FunctionKey; + keycode_map[Key::F5] = NSF5FunctionKey; + keycode_map[Key::F6] = NSF6FunctionKey; + keycode_map[Key::F7] = NSF7FunctionKey; + keycode_map[Key::F8] = NSF8FunctionKey; + keycode_map[Key::F9] = NSF9FunctionKey; + keycode_map[Key::F10] = NSF10FunctionKey; + keycode_map[Key::F11] = NSF11FunctionKey; + keycode_map[Key::F12] = NSF12FunctionKey; + keycode_map[Key::F13] = NSF13FunctionKey; + keycode_map[Key::F14] = NSF14FunctionKey; + keycode_map[Key::F15] = NSF15FunctionKey; + keycode_map[Key::F16] = NSF16FunctionKey; + keycode_map[Key::F17] = NSF17FunctionKey; + keycode_map[Key::F18] = NSF18FunctionKey; + keycode_map[Key::F19] = NSF19FunctionKey; + keycode_map[Key::F20] = NSF20FunctionKey; + keycode_map[Key::F21] = NSF21FunctionKey; + keycode_map[Key::F22] = NSF22FunctionKey; + keycode_map[Key::F23] = NSF23FunctionKey; + keycode_map[Key::F24] = NSF24FunctionKey; + keycode_map[Key::F25] = NSF25FunctionKey; + keycode_map[Key::F26] = NSF26FunctionKey; + keycode_map[Key::F27] = NSF27FunctionKey; + keycode_map[Key::F28] = NSF28FunctionKey; + keycode_map[Key::F29] = NSF29FunctionKey; + keycode_map[Key::F30] = NSF30FunctionKey; + keycode_map[Key::F31] = NSF31FunctionKey; + keycode_map[Key::F32] = NSF32FunctionKey; + keycode_map[Key::F33] = NSF33FunctionKey; + keycode_map[Key::F34] = NSF34FunctionKey; + keycode_map[Key::F35] = NSF35FunctionKey; + keycode_map[Key::MENU] = NSMenuFunctionKey; + keycode_map[Key::HELP] = NSHelpFunctionKey; + keycode_map[Key::STOP] = NSStopFunctionKey; + keycode_map[Key::LAUNCH0] = NSUserFunctionKey; + keycode_map[Key::SPACE] = 0x0020; + keycode_map[Key::EXCLAM] = '!'; + keycode_map[Key::QUOTEDBL] = '\"'; + keycode_map[Key::NUMBERSIGN] = '#'; + keycode_map[Key::DOLLAR] = '$'; + keycode_map[Key::PERCENT] = '\%'; + keycode_map[Key::AMPERSAND] = '&'; + keycode_map[Key::APOSTROPHE] = '\''; + keycode_map[Key::PARENLEFT] = '('; + keycode_map[Key::PARENRIGHT] = ')'; + keycode_map[Key::ASTERISK] = '*'; + keycode_map[Key::PLUS] = '+'; + keycode_map[Key::COMMA] = ','; + keycode_map[Key::MINUS] = '-'; + keycode_map[Key::PERIOD] = '.'; + keycode_map[Key::SLASH] = '/'; + keycode_map[Key::KEY_0] = '0'; + keycode_map[Key::KEY_1] = '1'; + keycode_map[Key::KEY_2] = '2'; + keycode_map[Key::KEY_3] = '3'; + keycode_map[Key::KEY_4] = '4'; + keycode_map[Key::KEY_5] = '5'; + keycode_map[Key::KEY_6] = '6'; + keycode_map[Key::KEY_7] = '7'; + keycode_map[Key::KEY_8] = '8'; + keycode_map[Key::KEY_9] = '9'; + keycode_map[Key::COLON] = ':'; + keycode_map[Key::SEMICOLON] = ';'; + keycode_map[Key::LESS] = '<'; + keycode_map[Key::EQUAL] = '='; + keycode_map[Key::GREATER] = '>'; + keycode_map[Key::QUESTION] = '?'; + keycode_map[Key::AT] = '@'; + keycode_map[Key::A] = 'a'; + keycode_map[Key::B] = 'b'; + keycode_map[Key::C] = 'c'; + keycode_map[Key::D] = 'd'; + keycode_map[Key::E] = 'e'; + keycode_map[Key::F] = 'f'; + keycode_map[Key::G] = 'g'; + keycode_map[Key::H] = 'h'; + keycode_map[Key::I] = 'i'; + keycode_map[Key::J] = 'j'; + keycode_map[Key::K] = 'k'; + keycode_map[Key::L] = 'l'; + keycode_map[Key::M] = 'm'; + keycode_map[Key::N] = 'n'; + keycode_map[Key::O] = 'o'; + keycode_map[Key::P] = 'p'; + keycode_map[Key::Q] = 'q'; + keycode_map[Key::R] = 'r'; + keycode_map[Key::S] = 's'; + keycode_map[Key::T] = 't'; + keycode_map[Key::U] = 'u'; + keycode_map[Key::V] = 'v'; + keycode_map[Key::W] = 'w'; + keycode_map[Key::X] = 'x'; + keycode_map[Key::Y] = 'y'; + keycode_map[Key::Z] = 'z'; + keycode_map[Key::BRACKETLEFT] = '['; + keycode_map[Key::BACKSLASH] = '\\'; + keycode_map[Key::BRACKETRIGHT] = ']'; + keycode_map[Key::ASCIICIRCUM] = '^'; + keycode_map[Key::UNDERSCORE] = '_'; + keycode_map[Key::QUOTELEFT] = '`'; + keycode_map[Key::BRACELEFT] = '{'; + keycode_map[Key::BAR] = '|'; + keycode_map[Key::BRACERIGHT] = '}'; + keycode_map[Key::ASCIITILDE] = '~'; } -// Keyboard symbol translation table. -static const Key _macos_to_godot_table[128] = { - /* 00 */ Key::A, - /* 01 */ Key::S, - /* 02 */ Key::D, - /* 03 */ Key::F, - /* 04 */ Key::H, - /* 05 */ Key::G, - /* 06 */ Key::Z, - /* 07 */ Key::X, - /* 08 */ Key::C, - /* 09 */ Key::V, - /* 0a */ Key::SECTION, /* ISO Section */ - /* 0b */ Key::B, - /* 0c */ Key::Q, - /* 0d */ Key::W, - /* 0e */ Key::E, - /* 0f */ Key::R, - /* 10 */ Key::Y, - /* 11 */ Key::T, - /* 12 */ Key::KEY_1, - /* 13 */ Key::KEY_2, - /* 14 */ Key::KEY_3, - /* 15 */ Key::KEY_4, - /* 16 */ Key::KEY_6, - /* 17 */ Key::KEY_5, - /* 18 */ Key::EQUAL, - /* 19 */ Key::KEY_9, - /* 1a */ Key::KEY_7, - /* 1b */ Key::MINUS, - /* 1c */ Key::KEY_8, - /* 1d */ Key::KEY_0, - /* 1e */ Key::BRACERIGHT, - /* 1f */ Key::O, - /* 20 */ Key::U, - /* 21 */ Key::BRACELEFT, - /* 22 */ Key::I, - /* 23 */ Key::P, - /* 24 */ Key::ENTER, - /* 25 */ Key::L, - /* 26 */ Key::J, - /* 27 */ Key::APOSTROPHE, - /* 28 */ Key::K, - /* 29 */ Key::SEMICOLON, - /* 2a */ Key::BACKSLASH, - /* 2b */ Key::COMMA, - /* 2c */ Key::SLASH, - /* 2d */ Key::N, - /* 2e */ Key::M, - /* 2f */ Key::PERIOD, - /* 30 */ Key::TAB, - /* 31 */ Key::SPACE, - /* 32 */ Key::QUOTELEFT, - /* 33 */ Key::BACKSPACE, - /* 34 */ Key::UNKNOWN, - /* 35 */ Key::ESCAPE, - /* 36 */ Key::META, - /* 37 */ Key::META, - /* 38 */ Key::SHIFT, - /* 39 */ Key::CAPSLOCK, - /* 3a */ Key::ALT, - /* 3b */ Key::CTRL, - /* 3c */ Key::SHIFT, - /* 3d */ Key::ALT, - /* 3e */ Key::CTRL, - /* 3f */ Key::UNKNOWN, /* Function */ - /* 40 */ Key::F17, - /* 41 */ Key::KP_PERIOD, - /* 42 */ Key::UNKNOWN, - /* 43 */ Key::KP_MULTIPLY, - /* 44 */ Key::UNKNOWN, - /* 45 */ Key::KP_ADD, - /* 46 */ Key::UNKNOWN, - /* 47 */ Key::NUMLOCK, /* Really KeypadClear... */ - /* 48 */ Key::VOLUMEUP, /* VolumeUp */ - /* 49 */ Key::VOLUMEDOWN, /* VolumeDown */ - /* 4a */ Key::VOLUMEMUTE, /* Mute */ - /* 4b */ Key::KP_DIVIDE, - /* 4c */ Key::KP_ENTER, - /* 4d */ Key::UNKNOWN, - /* 4e */ Key::KP_SUBTRACT, - /* 4f */ Key::F18, - /* 50 */ Key::F19, - /* 51 */ Key::EQUAL, /* KeypadEqual */ - /* 52 */ Key::KP_0, - /* 53 */ Key::KP_1, - /* 54 */ Key::KP_2, - /* 55 */ Key::KP_3, - /* 56 */ Key::KP_4, - /* 57 */ Key::KP_5, - /* 58 */ Key::KP_6, - /* 59 */ Key::KP_7, - /* 5a */ Key::F20, - /* 5b */ Key::KP_8, - /* 5c */ Key::KP_9, - /* 5d */ Key::YEN, /* JIS Yen */ - /* 5e */ Key::UNDERSCORE, /* JIS Underscore */ - /* 5f */ Key::COMMA, /* JIS KeypadComma */ - /* 60 */ Key::F5, - /* 61 */ Key::F6, - /* 62 */ Key::F7, - /* 63 */ Key::F3, - /* 64 */ Key::F8, - /* 65 */ Key::F9, - /* 66 */ Key::UNKNOWN, /* JIS Eisu */ - /* 67 */ Key::F11, - /* 68 */ Key::UNKNOWN, /* JIS Kana */ - /* 69 */ Key::F13, - /* 6a */ Key::F16, - /* 6b */ Key::F14, - /* 6c */ Key::UNKNOWN, - /* 6d */ Key::F10, - /* 6e */ Key::MENU, - /* 6f */ Key::F12, - /* 70 */ Key::UNKNOWN, - /* 71 */ Key::F15, - /* 72 */ Key::INSERT, /* Really Help... */ - /* 73 */ Key::HOME, - /* 74 */ Key::PAGEUP, - /* 75 */ Key::KEY_DELETE, - /* 76 */ Key::F4, - /* 77 */ Key::END, - /* 78 */ Key::F2, - /* 79 */ Key::PAGEDOWN, - /* 7a */ Key::F1, - /* 7b */ Key::LEFT, - /* 7c */ Key::RIGHT, - /* 7d */ Key::DOWN, - /* 7e */ Key::UP, - /* 7f */ Key::UNKNOWN, -}; +bool KeyMappingMacOS::is_numpad_key(unsigned int p_key) { + return numpad_keys.has(p_key); +} // Translates a OS X keycode to a Godot keycode. -Key KeyMappingMacOS::translate_key(unsigned int key) { - if (key >= 128) { - return Key::UNKNOWN; +Key KeyMappingMacOS::translate_key(unsigned int p_key) { + const Key *key = keysym_map.getptr(p_key); + if (key) { + return *key; } - - return _macos_to_godot_table[key]; + return Key::NONE; } // Translates a Godot keycode back to a macOS keycode. -unsigned int KeyMappingMacOS::unmap_key(Key key) { - for (int i = 0; i <= 126; i++) { - if (_macos_to_godot_table[i] == key) { - return i; - } +unsigned int KeyMappingMacOS::unmap_key(Key p_key) { + const unsigned int *key = keysym_map_inv.getptr(p_key); + if (key) { + return *key; } return 127; } -struct _KeyCodeMap { - UniChar kchar; - Key kcode; -}; - -static const _KeyCodeMap _keycodes[55] = { - { '`', Key::QUOTELEFT }, - { '~', Key::ASCIITILDE }, - { '0', Key::KEY_0 }, - { '1', Key::KEY_1 }, - { '2', Key::KEY_2 }, - { '3', Key::KEY_3 }, - { '4', Key::KEY_4 }, - { '5', Key::KEY_5 }, - { '6', Key::KEY_6 }, - { '7', Key::KEY_7 }, - { '8', Key::KEY_8 }, - { '9', Key::KEY_9 }, - { '-', Key::MINUS }, - { '_', Key::UNDERSCORE }, - { '=', Key::EQUAL }, - { '+', Key::PLUS }, - { 'q', Key::Q }, - { 'w', Key::W }, - { 'e', Key::E }, - { 'r', Key::R }, - { 't', Key::T }, - { 'y', Key::Y }, - { 'u', Key::U }, - { 'i', Key::I }, - { 'o', Key::O }, - { 'p', Key::P }, - { '[', Key::BRACELEFT }, - { ']', Key::BRACERIGHT }, - { '{', Key::BRACELEFT }, - { '}', Key::BRACERIGHT }, - { 'a', Key::A }, - { 's', Key::S }, - { 'd', Key::D }, - { 'f', Key::F }, - { 'g', Key::G }, - { 'h', Key::H }, - { 'j', Key::J }, - { 'k', Key::K }, - { 'l', Key::L }, - { ';', Key::SEMICOLON }, - { ':', Key::COLON }, - { '\'', Key::APOSTROPHE }, - { '\"', Key::QUOTEDBL }, - { '\\', Key::BACKSLASH }, - { '#', Key::NUMBERSIGN }, - { 'z', Key::Z }, - { 'x', Key::X }, - { 'c', Key::C }, - { 'v', Key::V }, - { 'b', Key::B }, - { 'n', Key::N }, - { 'm', Key::M }, - { ',', Key::COMMA }, - { '.', Key::PERIOD }, - { '/', Key::SLASH } -}; - // Remap key according to current keyboard layout. -Key KeyMappingMacOS::remap_key(unsigned int key, unsigned int state) { - if (is_numpad_key(key)) { - return translate_key(key); +Key KeyMappingMacOS::remap_key(unsigned int p_key, unsigned int p_state, bool p_unicode) { + if (is_numpad_key(p_key)) { + return translate_key(p_key); } TISInputSourceRef current_keyboard = TISCopyCurrentKeyboardInputSource(); if (!current_keyboard) { - return translate_key(key); + return translate_key(p_key); } CFDataRef layout_data = (CFDataRef)TISGetInputSourceProperty(current_keyboard, kTISPropertyUnicodeKeyLayoutData); if (!layout_data) { - return translate_key(key); + return translate_key(p_key); } const UCKeyboardLayout *keyboard_layout = (const UCKeyboardLayout *)CFDataGetBytePtr(layout_data); + String keysym; UInt32 keys_down = 0; - UniChar chars[4]; - UniCharCount real_length; + UniChar chars[256] = {}; + UniCharCount real_length = 0; OSStatus err = UCKeyTranslate(keyboard_layout, - key, + p_key, kUCKeyActionDisplay, - (state >> 8) & 0xFF, + (p_unicode) ? 0 : (p_state >> 8) & 0xFF, LMGetKbdType(), kUCKeyTranslateNoDeadKeysBit, &keys_down, @@ -312,165 +380,26 @@ Key KeyMappingMacOS::remap_key(unsigned int key, unsigned int state) { chars); if (err != noErr) { - return translate_key(key); + return translate_key(p_key); } - for (unsigned int i = 0; i < 55; i++) { - if (_keycodes[i].kchar == chars[0]) { - return _keycodes[i].kcode; - } + keysym = String::utf16((char16_t *)chars, real_length); + if (keysym.is_empty()) { + return translate_key(p_key); } - return translate_key(key); -} - -struct _KeyCodeText { - Key code; - char32_t text; -}; -static const _KeyCodeText _native_keycodes[] = { - /* clang-format off */ - {Key::ESCAPE ,0x001B}, - {Key::TAB ,0x0009}, - {Key::BACKTAB ,0x007F}, - {Key::BACKSPACE ,0x0008}, - {Key::ENTER ,0x000D}, - {Key::INSERT ,NSInsertFunctionKey}, - {Key::KEY_DELETE ,0x007F}, - {Key::PAUSE ,NSPauseFunctionKey}, - {Key::PRINT ,NSPrintScreenFunctionKey}, - {Key::SYSREQ ,NSSysReqFunctionKey}, - {Key::CLEAR ,NSClearLineFunctionKey}, - {Key::HOME ,0x2196}, - {Key::END ,0x2198}, - {Key::LEFT ,0x001C}, - {Key::UP ,0x001E}, - {Key::RIGHT ,0x001D}, - {Key::DOWN ,0x001F}, - {Key::PAGEUP ,0x21DE}, - {Key::PAGEDOWN ,0x21DF}, - {Key::NUMLOCK ,NSClearLineFunctionKey}, - {Key::SCROLLLOCK ,NSScrollLockFunctionKey}, - {Key::F1 ,NSF1FunctionKey}, - {Key::F2 ,NSF2FunctionKey}, - {Key::F3 ,NSF3FunctionKey}, - {Key::F4 ,NSF4FunctionKey}, - {Key::F5 ,NSF5FunctionKey}, - {Key::F6 ,NSF6FunctionKey}, - {Key::F7 ,NSF7FunctionKey}, - {Key::F8 ,NSF8FunctionKey}, - {Key::F9 ,NSF9FunctionKey}, - {Key::F10 ,NSF10FunctionKey}, - {Key::F11 ,NSF11FunctionKey}, - {Key::F12 ,NSF12FunctionKey}, - {Key::F13 ,NSF13FunctionKey}, - {Key::F14 ,NSF14FunctionKey}, - {Key::F15 ,NSF15FunctionKey}, - {Key::F16 ,NSF16FunctionKey}, - {Key::F17 ,NSF17FunctionKey}, - {Key::F18 ,NSF18FunctionKey}, - {Key::F19 ,NSF19FunctionKey}, - {Key::F20 ,NSF20FunctionKey}, - {Key::F21 ,NSF21FunctionKey}, - {Key::F22 ,NSF22FunctionKey}, - {Key::F23 ,NSF23FunctionKey}, - {Key::F24 ,NSF24FunctionKey}, - {Key::F25 ,NSF25FunctionKey}, - {Key::F26 ,NSF26FunctionKey}, - {Key::F27 ,NSF27FunctionKey}, - {Key::F28 ,NSF28FunctionKey}, - {Key::F29 ,NSF29FunctionKey}, - {Key::F30 ,NSF30FunctionKey}, - {Key::F31 ,NSF31FunctionKey}, - {Key::F32 ,NSF32FunctionKey}, - {Key::F33 ,NSF33FunctionKey}, - {Key::F34 ,NSF34FunctionKey}, - {Key::F35 ,NSF35FunctionKey}, - {Key::MENU ,NSMenuFunctionKey}, - {Key::HELP ,NSHelpFunctionKey}, - {Key::STOP ,NSStopFunctionKey}, - {Key::LAUNCH0 ,NSUserFunctionKey}, - {Key::SPACE ,0x0020}, - {Key::EXCLAM ,'!'}, - {Key::QUOTEDBL ,'\"'}, - {Key::NUMBERSIGN ,'#'}, - {Key::DOLLAR ,'$'}, - {Key::PERCENT ,'\%'}, - {Key::AMPERSAND ,'&'}, - {Key::APOSTROPHE ,'\''}, - {Key::PARENLEFT ,'('}, - {Key::PARENRIGHT ,')'}, - {Key::ASTERISK ,'*'}, - {Key::PLUS ,'+'}, - {Key::COMMA ,','}, - {Key::MINUS ,'-'}, - {Key::PERIOD ,'.'}, - {Key::SLASH ,'/'}, - {Key::KEY_0 ,'0'}, - {Key::KEY_1 ,'1'}, - {Key::KEY_2 ,'2'}, - {Key::KEY_3 ,'3'}, - {Key::KEY_4 ,'4'}, - {Key::KEY_5 ,'5'}, - {Key::KEY_6 ,'6'}, - {Key::KEY_7 ,'7'}, - {Key::KEY_8 ,'8'}, - {Key::KEY_9 ,'9'}, - {Key::COLON ,':'}, - {Key::SEMICOLON ,';'}, - {Key::LESS ,'<'}, - {Key::EQUAL ,'='}, - {Key::GREATER ,'>'}, - {Key::QUESTION ,'?'}, - {Key::AT ,'@'}, - {Key::A ,'a'}, - {Key::B ,'b'}, - {Key::C ,'c'}, - {Key::D ,'d'}, - {Key::E ,'e'}, - {Key::F ,'f'}, - {Key::G ,'g'}, - {Key::H ,'h'}, - {Key::I ,'i'}, - {Key::J ,'j'}, - {Key::K ,'k'}, - {Key::L ,'l'}, - {Key::M ,'m'}, - {Key::N ,'n'}, - {Key::O ,'o'}, - {Key::P ,'p'}, - {Key::Q ,'q'}, - {Key::R ,'r'}, - {Key::S ,'s'}, - {Key::T ,'t'}, - {Key::U ,'u'}, - {Key::V ,'v'}, - {Key::W ,'w'}, - {Key::X ,'x'}, - {Key::Y ,'y'}, - {Key::Z ,'z'}, - {Key::BRACKETLEFT ,'['}, - {Key::BACKSLASH ,'\\'}, - {Key::BRACKETRIGHT ,']'}, - {Key::ASCIICIRCUM ,'^'}, - {Key::UNDERSCORE ,'_'}, - {Key::QUOTELEFT ,'`'}, - {Key::BRACELEFT ,'{'}, - {Key::BAR ,'|'}, - {Key::BRACERIGHT ,'}'}, - {Key::ASCIITILDE ,'~'}, - {Key::NONE ,0x0000} - /* clang-format on */ -}; + char32_t c = keysym[0]; + if (p_unicode) { + return fix_key_label(c, translate_key(p_key)); + } else { + return fix_keycode(c, translate_key(p_key)); + } +} String KeyMappingMacOS::keycode_get_native_string(Key p_keycode) { - const _KeyCodeText *kct = &_native_keycodes[0]; - - while (kct->text) { - if (kct->code == p_keycode) { - return String::chr(kct->text); - } - kct++; + const char32_t *key = keycode_map.getptr(p_keycode); + if (key) { + return String::chr(*key); } return String(); } |