From 42e619c01e26bdf85f458a8f86498112adf2eee2 Mon Sep 17 00:00:00 2001 From: gregcsokas Date: Mon, 13 Jun 2022 18:44:44 +0200 Subject: [PATCH] Adding function key support from F17 to F35 OSX supports everything by default, Linux is also capable of supporting every function key, Windows as I know support only up to F24 --- core/core_constants.cpp | 19 +++ core/os/keyboard.cpp | 38 ++++++ core/os/keyboard.h | 115 ++++++++++------- doc/classes/@GlobalScope.xml | 153 ++++++++++++++++------- platform/linuxbsd/key_mapping_x11.cpp | 42 +++++++ platform/osx/key_mapping_osx.mm | 29 ++++- platform/windows/key_mapping_windows.cpp | 17 ++- 7 files changed, 311 insertions(+), 102 deletions(-) diff --git a/core/core_constants.cpp b/core/core_constants.cpp index 4f22c996569..eb5a8226d75 100644 --- a/core/core_constants.cpp +++ b/core/core_constants.cpp @@ -213,6 +213,25 @@ void register_global_constants() { BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F14); BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F15); BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F16); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F17); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F18); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F19); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F20); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F21); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F22); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F23); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F24); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F25); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F26); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F27); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F28); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F29); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F30); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F31); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F32); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F33); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F34); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F35); BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KP_MULTIPLY); BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KP_DIVIDE); BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KP_SUBTRACT); diff --git a/core/os/keyboard.cpp b/core/os/keyboard.cpp index 24907d34c8b..3e690991d9a 100644 --- a/core/os/keyboard.cpp +++ b/core/os/keyboard.cpp @@ -86,6 +86,25 @@ static const _KeyCodeText _keycodes[] = { {Key::F14 ,"F14"}, {Key::F15 ,"F15"}, {Key::F16 ,"F16"}, + {Key::F17 ,"F17"}, + {Key::F18 ,"F18"}, + {Key::F19 ,"F19"}, + {Key::F20 ,"F20"}, + {Key::F21 ,"F21"}, + {Key::F22 ,"F22"}, + {Key::F23 ,"F23"}, + {Key::F24 ,"F24"}, + {Key::F25 ,"F25"}, + {Key::F26 ,"F26"}, + {Key::F27 ,"F27"}, + {Key::F28 ,"F28"}, + {Key::F29 ,"F29"}, + {Key::F30 ,"F30"}, + {Key::F31 ,"F31"}, + {Key::F32 ,"F32"}, + {Key::F33 ,"F33"}, + {Key::F34 ,"F34"}, + {Key::F35 ,"F35"}, {Key::KP_MULTIPLY ,"Kp Multiply"}, {Key::KP_DIVIDE ,"Kp Divide"}, {Key::KP_SUBTRACT ,"Kp Subtract"}, @@ -333,6 +352,25 @@ bool keycode_has_unicode(Key p_keycode) { case Key::F14: case Key::F15: case Key::F16: + case Key::F17: + case Key::F18: + case Key::F19: + case Key::F20: + case Key::F21: + case Key::F22: + case Key::F23: + case Key::F24: + case Key::F25: + case Key::F26: + case Key::F27: + case Key::F28: + case Key::F29: + case Key::F30: + case Key::F31: + case Key::F32: + case Key::F33: + case Key::F34: + case Key::F35: case Key::SUPER_L: case Key::SUPER_R: case Key::MENU: diff --git a/core/os/keyboard.h b/core/os/keyboard.h index 3176a8a210c..517a53e5057 100644 --- a/core/os/keyboard.h +++ b/core/os/keyboard.h @@ -85,6 +85,25 @@ enum class Key { F14 = SPECIAL | 0x29, F15 = SPECIAL | 0x2A, F16 = SPECIAL | 0x2B, + F17 = SPECIAL | 0x2C, + F18 = SPECIAL | 0x2D, + F19 = SPECIAL | 0x2E, + F20 = SPECIAL | 0x2F, + F21 = SPECIAL | 0x30, + F22 = SPECIAL | 0x31, + F23 = SPECIAL | 0x32, + F24 = SPECIAL | 0x33, + F25 = SPECIAL | 0x34, + F26 = SPECIAL | 0x35, + F27 = SPECIAL | 0x36, + F28 = SPECIAL | 0x37, + F29 = SPECIAL | 0x38, + F30 = SPECIAL | 0x39, + F31 = SPECIAL | 0x3A, + F32 = SPECIAL | 0x3B, + F33 = SPECIAL | 0x3C, + F34 = SPECIAL | 0x3D, + F35 = SPECIAL | 0x3E, KP_MULTIPLY = SPECIAL | 0x81, KP_DIVIDE = SPECIAL | 0x82, KP_SUBTRACT = SPECIAL | 0x83, @@ -100,54 +119,54 @@ enum class Key { KP_7 = SPECIAL | 0x8D, KP_8 = SPECIAL | 0x8E, KP_9 = SPECIAL | 0x8F, - SUPER_L = SPECIAL | 0x2C, - SUPER_R = SPECIAL | 0x2D, - MENU = SPECIAL | 0x2E, - HYPER_L = SPECIAL | 0x2F, - HYPER_R = SPECIAL | 0x30, - HELP = SPECIAL | 0x31, - DIRECTION_L = SPECIAL | 0x32, - DIRECTION_R = SPECIAL | 0x33, - BACK = SPECIAL | 0x40, - FORWARD = SPECIAL | 0x41, - STOP = SPECIAL | 0x42, - REFRESH = SPECIAL | 0x43, - VOLUMEDOWN = SPECIAL | 0x44, - VOLUMEMUTE = SPECIAL | 0x45, - VOLUMEUP = SPECIAL | 0x46, - BASSBOOST = SPECIAL | 0x47, - BASSUP = SPECIAL | 0x48, - BASSDOWN = SPECIAL | 0x49, - TREBLEUP = SPECIAL | 0x4A, - TREBLEDOWN = SPECIAL | 0x4B, - MEDIAPLAY = SPECIAL | 0x4C, - MEDIASTOP = SPECIAL | 0x4D, - MEDIAPREVIOUS = SPECIAL | 0x4E, - MEDIANEXT = SPECIAL | 0x4F, - MEDIARECORD = SPECIAL | 0x50, - HOMEPAGE = SPECIAL | 0x51, - FAVORITES = SPECIAL | 0x52, - SEARCH = SPECIAL | 0x53, - STANDBY = SPECIAL | 0x54, - OPENURL = SPECIAL | 0x55, - LAUNCHMAIL = SPECIAL | 0x56, - LAUNCHMEDIA = SPECIAL | 0x57, - LAUNCH0 = SPECIAL | 0x58, - LAUNCH1 = SPECIAL | 0x59, - LAUNCH2 = SPECIAL | 0x5A, - LAUNCH3 = SPECIAL | 0x5B, - LAUNCH4 = SPECIAL | 0x5C, - LAUNCH5 = SPECIAL | 0x5D, - LAUNCH6 = SPECIAL | 0x5E, - LAUNCH7 = SPECIAL | 0x5F, - LAUNCH8 = SPECIAL | 0x60, - LAUNCH9 = SPECIAL | 0x61, - LAUNCHA = SPECIAL | 0x62, - LAUNCHB = SPECIAL | 0x63, - LAUNCHC = SPECIAL | 0x64, - LAUNCHD = SPECIAL | 0x65, - LAUNCHE = SPECIAL | 0x66, - LAUNCHF = SPECIAL | 0x67, + SUPER_L = SPECIAL | 0x40, + SUPER_R = SPECIAL | 0x41, + MENU = SPECIAL | 0x42, + HYPER_L = SPECIAL | 0x43, + HYPER_R = SPECIAL | 0x44, + HELP = SPECIAL | 0x45, + DIRECTION_L = SPECIAL | 0x46, + DIRECTION_R = SPECIAL | 0x47, + BACK = SPECIAL | 0x48, + FORWARD = SPECIAL | 0x49, + STOP = SPECIAL | 0x4A, + REFRESH = SPECIAL | 0x4B, + VOLUMEDOWN = SPECIAL | 0x4C, + VOLUMEMUTE = SPECIAL | 0x4D, + VOLUMEUP = SPECIAL | 0x4E, + BASSBOOST = SPECIAL | 0x4F, + BASSUP = SPECIAL | 0x50, + BASSDOWN = SPECIAL | 0x51, + TREBLEUP = SPECIAL | 0x52, + TREBLEDOWN = SPECIAL | 0x53, + MEDIAPLAY = SPECIAL | 0x54, + MEDIASTOP = SPECIAL | 0x55, + MEDIAPREVIOUS = SPECIAL | 0x56, + MEDIANEXT = SPECIAL | 0x57, + MEDIARECORD = SPECIAL | 0x58, + HOMEPAGE = SPECIAL | 0x59, + FAVORITES = SPECIAL | 0x5A, + SEARCH = SPECIAL | 0x5B, + STANDBY = SPECIAL | 0x5C, + OPENURL = SPECIAL | 0x5D, + LAUNCHMAIL = SPECIAL | 0x5E, + LAUNCHMEDIA = SPECIAL | 0x5F, + LAUNCH0 = SPECIAL | 0x60, + LAUNCH1 = SPECIAL | 0x61, + LAUNCH2 = SPECIAL | 0x62, + LAUNCH3 = SPECIAL | 0x63, + LAUNCH4 = SPECIAL | 0x64, + LAUNCH5 = SPECIAL | 0x65, + LAUNCH6 = SPECIAL | 0x66, + LAUNCH7 = SPECIAL | 0x67, + LAUNCH8 = SPECIAL | 0x68, + LAUNCH9 = SPECIAL | 0x69, + LAUNCHA = SPECIAL | 0x6A, + LAUNCHB = SPECIAL | 0x6B, + LAUNCHC = SPECIAL | 0x6C, + LAUNCHD = SPECIAL | 0x6D, + LAUNCHE = SPECIAL | 0x6E, + LAUNCHF = SPECIAL | 0x6F, UNKNOWN = SPECIAL | 0xFFFFFF, diff --git a/doc/classes/@GlobalScope.xml b/doc/classes/@GlobalScope.xml index 18ea29857bc..a4260a3f3f3 100644 --- a/doc/classes/@GlobalScope.xml +++ b/doc/classes/@GlobalScope.xml @@ -1414,6 +1414,63 @@ F16 key. + + F17 key. + + + F18 key. + + + F19 key. + + + F20 key. + + + F21 key. + + + F22 key. + + + F23 key. + + + F24 key. + + + F25 key. Only supported on macOS and Linux due to a Windows limitation. + + + F26 key. Only supported on macOS and Linux due to a Windows limitation. + + + F27 key. Only supported on macOS and Linux due to a Windows limitation. + + + F28 key. Only supported on macOS and Linux due to a Windows limitation. + + + F29 key. Only supported on macOS and Linux due to a Windows limitation. + + + F30 key. Only supported on macOS and Linux due to a Windows limitation. + + + F31 key. Only supported on macOS and Linux due to a Windows limitation. + + + F32 key. Only supported on macOS and Linux due to a Windows limitation. + + + F33 key. Only supported on macOS and Linux due to a Windows limitation. + + + F34 key. Only supported on macOS and Linux due to a Windows limitation. + + + F35 key. Only supported on macOS and Linux due to a Windows limitation. + Multiply (*) key on the numeric keypad. @@ -1459,148 +1516,148 @@ Number 9 on the numeric keypad. - + Left Super key (Windows key). - + Right Super key (Windows key). - + Context menu key. - + Left Hyper key. - + Right Hyper key. - + Help key. - + Left Direction key. - + Right Direction key. - + Media back key. Not to be confused with the Back button on an Android device. - + Media forward key. - + Media stop key. - + Media refresh key. - + Volume down key. - + Mute volume key. - + Volume up key. - + Bass Boost key. - + Bass up key. - + Bass down key. - + Treble up key. - + Treble down key. - + Media play key. - + Media stop key. - + Previous song key. - + Next song key. - + Media record key. - + Home page key. - + Favorites key. - + Search key. - + Standby key. - + Open URL / Launch Browser key. - + Launch Mail key. - + Launch Media key. - + Launch Shortcut 0 key. - + Launch Shortcut 1 key. - + Launch Shortcut 2 key. - + Launch Shortcut 3 key. - + Launch Shortcut 4 key. - + Launch Shortcut 5 key. - + Launch Shortcut 6 key. - + Launch Shortcut 7 key. - + Launch Shortcut 8 key. - + Launch Shortcut 9 key. - + Launch Shortcut A key. - + Launch Shortcut B key. - + Launch Shortcut C key. - + Launch Shortcut D key. - + Launch Shortcut E key. - + Launch Shortcut F key. diff --git a/platform/linuxbsd/key_mapping_x11.cpp b/platform/linuxbsd/key_mapping_x11.cpp index afe965e0380..047ee746710 100644 --- a/platform/linuxbsd/key_mapping_x11.cpp +++ b/platform/linuxbsd/key_mapping_x11.cpp @@ -135,6 +135,25 @@ static _XTranslatePair _xkeysym_to_keycode[] = { { XK_F14, Key::F14 }, { XK_F15, Key::F15 }, { XK_F16, Key::F16 }, + { XK_F17, Key::F17 }, + { XK_F18, Key::F18 }, + { XK_F19, Key::F19 }, + { XK_F20, Key::F20 }, + { XK_F21, Key::F21 }, + { XK_F22, Key::F22 }, + { XK_F23, Key::F23 }, + { XK_F24, Key::F24 }, + { XK_F25, Key::F25 }, + { XK_F26, Key::F26 }, + { XK_F27, Key::F27 }, + { XK_F28, Key::F28 }, + { XK_F29, Key::F29 }, + { XK_F30, Key::F30 }, + { XK_F31, Key::F31 }, + { XK_F32, Key::F32 }, + { XK_F33, Key::F33 }, + { XK_F34, Key::F34 }, + { XK_F35, Key::F35 }, // media keys { XF86XK_Back, Key::BACK }, @@ -294,6 +313,29 @@ static _TranslatePair _scancode_to_keycode[] = { { Key::SUPER_L, 0x85 }, { Key::SUPER_R, 0x86 }, { Key::MENU, 0x87 }, + { Key::F13, 0xBF }, + { Key::F14, 0xC0 }, + { Key::F15, 0xC1 }, + { Key::F16, 0xC2 }, + { Key::F17, 0xC3 }, + { Key::F18, 0xC4 }, + { Key::F19, 0xC5 }, + { Key::F20, 0xC6 }, + { Key::F21, 0xC7 }, + { Key::F22, 0xC8 }, + { Key::F23, 0xC9 }, + { Key::F24, 0xCA }, + { Key::F25, 0xCB }, + { Key::F26, 0xCC }, + { Key::F27, 0xCD }, + { Key::F28, 0xCE }, + { Key::F29, 0xCF }, + { Key::F30, 0xD0 }, + { Key::F31, 0xD1 }, + { Key::F32, 0xD2 }, + { Key::F33, 0xD3 }, + { Key::F34, 0xD4 }, + { Key::F35, 0xD5 }, { Key::UNKNOWN, 0 } }; diff --git a/platform/osx/key_mapping_osx.mm b/platform/osx/key_mapping_osx.mm index bfec45de589..0bf6bc7d1c3 100644 --- a/platform/osx/key_mapping_osx.mm +++ b/platform/osx/key_mapping_osx.mm @@ -130,7 +130,7 @@ static const Key _osx_to_godot_table[128] = { /* 3d */ Key::ALT, /* 3e */ Key::CTRL, /* 3f */ Key::UNKNOWN, /* Function */ - /* 40 */ Key::UNKNOWN, /* F17 */ + /* 40 */ Key::F17, /* 41 */ Key::KP_PERIOD, /* 42 */ Key::UNKNOWN, /* 43 */ Key::KP_MULTIPLY, @@ -145,8 +145,8 @@ static const Key _osx_to_godot_table[128] = { /* 4c */ Key::KP_ENTER, /* 4d */ Key::UNKNOWN, /* 4e */ Key::KP_SUBTRACT, - /* 4f */ Key::UNKNOWN, /* F18 */ - /* 50 */ Key::UNKNOWN, /* F19 */ + /* 4f */ Key::F18, + /* 50 */ Key::F19, /* 51 */ Key::EQUAL, /* KeypadEqual */ /* 52 */ Key::KP_0, /* 53 */ Key::KP_1, @@ -156,7 +156,7 @@ static const Key _osx_to_godot_table[128] = { /* 57 */ Key::KP_5, /* 58 */ Key::KP_6, /* 59 */ Key::KP_7, - /* 5a */ Key::UNKNOWN, /* F20 */ + /* 5a */ Key::F20, /* 5b */ Key::KP_8, /* 5c */ Key::KP_9, /* 5d */ Key::YEN, /* JIS Yen */ @@ -366,7 +366,26 @@ static const _KeyCodeText _native_keycodes[] = { {Key::F13 ,NSF13FunctionKey}, {Key::F14 ,NSF14FunctionKey}, {Key::F15 ,NSF15FunctionKey}, - {Key::F16 ,NSF16FunctionKey}, //* ... NSF35FunctionKey */ + {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}, diff --git a/platform/windows/key_mapping_windows.cpp b/platform/windows/key_mapping_windows.cpp index e32dc0d1a6d..2d8d68a575d 100644 --- a/platform/windows/key_mapping_windows.cpp +++ b/platform/windows/key_mapping_windows.cpp @@ -179,7 +179,14 @@ static _WinTranslatePair _vk_to_keycode[] = { { Key::F14, VK_F14 }, // (0x7D) { Key::F15, VK_F15 }, // (0x7E) { Key::F16, VK_F16 }, // (0x7F) - // We have no mappings for F17-F24. (0x80-87) + { Key::F17, VK_F17 }, // (0x80) + { Key::F18, VK_F18 }, // (0x81) + { Key::F19, VK_F19 }, // (0x82) + { Key::F20, VK_F20 }, // (0x83) + { Key::F21, VK_F21 }, // (0x84) + { Key::F22, VK_F22 }, // (0x85) + { Key::F23, VK_F23 }, // (0x86) + { Key::F24, VK_F24 }, // (0x87) // 0x88-8F are reserved for UI navigation. { Key::NUMLOCK, VK_NUMLOCK }, // (0x90) { Key::SCROLLLOCK, VK_SCROLL }, // (0x91) @@ -409,6 +416,14 @@ static _WinTranslatePair _scancode_to_keycode[] = { { Key::F14, 0x65 }, { Key::F15, 0x66 }, { Key::F16, 0x67 }, + { Key::F17, 0x68 }, + { Key::F18, 0x69 }, + { Key::F19, 0x6A }, + { Key::F20, 0x6B }, + { Key::F21, 0x6C }, + { Key::F22, 0x6D }, + { Key::F23, 0x6E }, + { Key::F24, 0x76 }, { Key::UNKNOWN, 0 } };