From d83aaf28928bf7a093560fb746f2b4c5160efc51 Mon Sep 17 00:00:00 2001 From: Patrick Desaulniers Date: Mon, 29 Jul 2019 14:02:39 -0400 Subject: [PATCH 1/8] Add keycodes support --- dgl/Widget.hpp | 1 + dgl/src/Window.cpp | 7 +- dgl/src/pugl/COPYING | 23 +++++++ dgl/src/pugl/pugl.h | 134 +++++++++++++++++++++++++++++++++++++- dgl/src/pugl/pugl_osx.m | 24 ++++++- dgl/src/pugl/pugl_win.cpp | 25 ++++++- dgl/src/pugl/pugl_x11.c | 30 ++++++++- 7 files changed, 236 insertions(+), 8 deletions(-) create mode 100644 dgl/src/pugl/COPYING diff --git a/dgl/Widget.hpp b/dgl/Widget.hpp index f8d7139d4..e398f6d79 100644 --- a/dgl/Widget.hpp +++ b/dgl/Widget.hpp @@ -85,6 +85,7 @@ class Widget struct KeyboardEvent : BaseEvent { bool press; uint key; + uint keycode; /** Constuctor */ KeyboardEvent() noexcept diff --git a/dgl/src/Window.cpp b/dgl/src/Window.cpp index 09c47ac41..b515c29b0 100644 --- a/dgl/src/Window.cpp +++ b/dgl/src/Window.cpp @@ -805,7 +805,7 @@ struct Window::PrivateData { fSelf->onDisplayAfter(); } - int onPuglKeyboard(const bool press, const uint key) + int onPuglKeyboard(const bool press, const uint key, const uint keycode) { DBGp("PUGL: onKeyboard : %i %i\n", press, key); @@ -818,6 +818,7 @@ struct Window::PrivateData { Widget::KeyboardEvent ev; ev.press = press; ev.key = key; + ev.keycode = keycode; ev.mod = static_cast(puglGetModifiers(fView)); ev.time = puglGetEventTimestamp(fView); @@ -1130,9 +1131,9 @@ struct Window::PrivateData { handlePtr->onPuglDisplay(); } - static int onKeyboardCallback(PuglView* view, bool press, uint32_t key) + static int onKeyboardCallback(PuglView* view, bool press, uint32_t key, uint32_t keycode) { - return handlePtr->onPuglKeyboard(press, key); + return handlePtr->onPuglKeyboard(press, key, keycode); } static int onSpecialCallback(PuglView* view, bool press, PuglKey key) diff --git a/dgl/src/pugl/COPYING b/dgl/src/pugl/COPYING new file mode 100644 index 000000000..3b99c6ff3 --- /dev/null +++ b/dgl/src/pugl/COPYING @@ -0,0 +1,23 @@ +Keycode handling is based on "Keycodes" by Dietrich Epp +https://github.com/depp/keycode + +(MIT license) + +Copyright 2011-2019 Dietrich Epp + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/dgl/src/pugl/pugl.h b/dgl/src/pugl/pugl.h index 20a381401..238ad43e7 100644 --- a/dgl/src/pugl/pugl.h +++ b/dgl/src/pugl/pugl.h @@ -122,6 +122,138 @@ typedef enum { PUGL_MOD_SUPER = 1 << 3 /**< Mod4/Command/Windows key */ } PuglMod; +/** + * Layout-independent keycodes. + */ +typedef enum { + /* Zero, does not correspond to any key. */ + PUGL_VK_None = 0, + + PUGL_VK_A = 4, + PUGL_VK_B = 5, + PUGL_VK_C = 6, + PUGL_VK_D = 7, + PUGL_VK_E = 8, + PUGL_VK_F = 9, + PUGL_VK_G = 10, + PUGL_VK_H = 11, + PUGL_VK_I = 12, + PUGL_VK_J = 13, + PUGL_VK_K = 14, + PUGL_VK_L = 15, + PUGL_VK_M = 16, + PUGL_VK_N = 17, + PUGL_VK_O = 18, + PUGL_VK_P = 19, + PUGL_VK_Q = 20, + PUGL_VK_R = 21, + PUGL_VK_S = 22, + PUGL_VK_T = 23, + PUGL_VK_U = 24, + PUGL_VK_V = 25, + PUGL_VK_W = 26, + PUGL_VK_X = 27, + PUGL_VK_Y = 28, + PUGL_VK_Z = 29, + PUGL_VK_1 = 30, + PUGL_VK_2 = 31, + PUGL_VK_3 = 32, + PUGL_VK_4 = 33, + PUGL_VK_5 = 34, + PUGL_VK_6 = 35, + PUGL_VK_7 = 36, + PUGL_VK_8 = 37, + PUGL_VK_9 = 38, + PUGL_VK_0 = 39, + PUGL_VK_Escape = 41, + PUGL_VK_Delete = 42, + PUGL_VK_Tab = 43, + PUGL_VK_Space = 44, + PUGL_VK_Minus = 45, + PUGL_VK_Equals = 46, + PUGL_VK_LeftBracket = 47, + PUGL_VK_RightBracket = 48, + PUGL_VK_Backslash = 49, + PUGL_VK_Semicolon = 51, + PUGL_VK_Quote = 52, + PUGL_VK_Grave = 53, + PUGL_VK_Comma = 54, + PUGL_VK_Period = 55, + PUGL_VK_Slash = 56, + PUGL_VK_CapsLock = 57, + PUGL_VK_F1 = 58, + PUGL_VK_F2 = 59, + PUGL_VK_F3 = 60, + PUGL_VK_F4 = 61, + PUGL_VK_F5 = 62, + PUGL_VK_F6 = 63, + PUGL_VK_F7 = 64, + PUGL_VK_F8 = 65, + PUGL_VK_F9 = 66, + PUGL_VK_F10 = 67, + PUGL_VK_F11 = 68, + PUGL_VK_F12 = 69, + PUGL_VK_PrintScreen = 70, + PUGL_VK_ScrollLock = 71, + PUGL_VK_Pause = 72, + PUGL_VK_Insert = 73, + PUGL_VK_Home = 74, + PUGL_VK_PageUp = 75, + PUGL_VK_DeleteForward = 76, + PUGL_VK_End = 77, + PUGL_VK_PageDown = 78, + PUGL_VK_Right = 79, + PUGL_VK_Left = 80, + PUGL_VK_Down = 81, + PUGL_VK_Up = 82, + PUGL_VK_KP_NumLock = 83, + PUGL_VK_KP_Divide = 84, + PUGL_VK_KP_Multiply = 85, + PUGL_VK_KP_Subtract = 86, + PUGL_VK_KP_Add = 87, + PUGL_VK_KP_Enter = 88, + PUGL_VK_KP_1 = 89, + PUGL_VK_KP_2 = 90, + PUGL_VK_KP_3 = 91, + PUGL_VK_KP_4 = 92, + PUGL_VK_KP_5 = 93, + PUGL_VK_KP_6 = 94, + PUGL_VK_KP_7 = 95, + PUGL_VK_KP_8 = 96, + PUGL_VK_KP_9 = 97, + PUGL_VK_KP_0 = 98, + PUGL_VKPoint = 99, + PUGL_VK_NonUSBackslash = 100, + PUGL_VK_KP_Equals = 103, + PUGL_VK_F13 = 104, + PUGL_VK_F14 = 105, + PUGL_VK_F15 = 106, + PUGL_VK_F16 = 107, + PUGL_VK_F17 = 108, + PUGL_VK_F18 = 109, + PUGL_VK_F19 = 110, + PUGL_VK_F20 = 111, + PUGL_VK_F21 = 112, + PUGL_VK_F22 = 113, + PUGL_VK_F23 = 114, + PUGL_VK_F24 = 115, + PUGL_VK_Help = 117, + PUGL_VK_Menu = 118, + PUGL_VK_Mute = 127, + PUGL_VK_SysReq = 154, + PUGL_VK_Return = 158, + PUGL_VK_KP_Clear = 216, + PUGL_VK_KP_Decimal = 220, + PUGL_VK_LeftControl = 224, + PUGL_VK_LeftShift = 225, + PUGL_VK_LeftAlt = 226, + PUGL_VK_LeftGUI = 227, + PUGL_VK_RightControl = 228, + PUGL_VK_RightShift = 229, + PUGL_VK_RightAlt = 230, + PUGL_VK_RightGUI = 231 +} PuglKeyCodes; + /** Handle for opaque user data. */ @@ -144,7 +276,7 @@ typedef void (*PuglDisplayFunc)(PuglView* view); @param key Unicode point of the key pressed. @return 0 if event was handled, otherwise send event to parent window. */ -typedef int (*PuglKeyboardFunc)(PuglView* view, bool press, uint32_t key); +typedef int (*PuglKeyboardFunc)(PuglView* view, bool press, uint32_t key, uint32_t keycode); /** A function called when the pointer moves. diff --git a/dgl/src/pugl/pugl_osx.m b/dgl/src/pugl/pugl_osx.m index 80b99304c..ea1b16b1a 100644 --- a/dgl/src/pugl/pugl_osx.m +++ b/dgl/src/pugl/pugl_osx.m @@ -121,6 +121,24 @@ - (void) setPuglTrackingArea:(NSTrackingArea *)area; return mods; } +static unsigned +scancodeToHID(unsigned scancode) +{ + const unsigned char KEYCODE_MACOS_TO_HID[128] = { + 4,22,7,9,11,10,29,27,6,25,0,5,20,26,8,21,28,23,30,31,32,33,35,34,46,38,36, + 45,37,39,48,18,24,47,12,19,158,15,13,52,14,51,49,54,56,17,16,55,43,44,53,42, + 0,41,231,227,225,57,226,224,229,230,228,0,108,220,0,85,0,87,0,216,0,0,127, + 84,88,0,86,109,110,103,98,89,90,91,92,93,94,95,111,96,97,0,0,0,62,63,64,60, + 65,66,0,68,0,104,107,105,0,67,0,69,0,106,117,74,75,76,61,77,59,78,58,80,79, + 81,82,0 + }; + + if (scancode >= 128) + return 0; + + return KEYCODE_MACOS_TO_HID[scancode]; +} + static int getFixedAppKitButton(NSInteger button) { @@ -253,8 +271,9 @@ - (void) setPuglTrackingArea:(NSTrackingArea *)area; if (puglview->keyboardFunc && !(puglview->ignoreKeyRepeat && [event isARepeat])) { NSString* chars = [event characters]; + unsigned keycode = scancodeToHID([event keyCode]); puglview->mods = getModifiers(puglview, event); - puglview->keyboardFunc(puglview, true, [chars characterAtIndex:0]); + puglview->keyboardFunc(puglview, true, [chars characterAtIndex:0], keycode); } } @@ -265,8 +284,9 @@ - (void) setPuglTrackingArea:(NSTrackingArea *)area; if (puglview->keyboardFunc) { NSString* chars = [event characters]; + unsigned keycode = scancodeToHID([event keyCode]); puglview->mods = getModifiers(puglview, event); - puglview->keyboardFunc(puglview, false, [chars characterAtIndex:0]); + puglview->keyboardFunc(puglview, false, [chars characterAtIndex:0], keycode); } } diff --git a/dgl/src/pugl/pugl_win.cpp b/dgl/src/pugl/pugl_win.cpp index d8b3866db..4dd43ca92 100644 --- a/dgl/src/pugl/pugl_win.cpp +++ b/dgl/src/pugl/pugl_win.cpp @@ -377,6 +377,26 @@ setModifiers(PuglView* view) view->mods |= (GetKeyState(VK_RWIN) < 0) ? PUGL_MOD_SUPER : 0; } +static unsigned +keycodeToHID(unsigned keycode) +{ + const unsigned char KEYCODE_WINDOWS_TO_HID[256] = { + 0,41,30,31,32,33,34,35,36,37,38,39,45,46,42,43,20,26,8,21,23,28,24,12,18,19, + 47,48,158,224,4,22,7,9,10,11,13,14,15,51,52,53,225,49,29,27,6,25,5,17,16,54, + 55,56,229,0,226,0,57,58,59,60,61,62,63,64,65,66,67,72,71,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,68,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,228,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,70,230,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,74,82,75,0,80,0,79,0,77,81,78,73,76,0,0,0,0,0,0,0,227,231, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + }; + + if (keycode >= 256) + return 0; + + return KEYCODE_WINDOWS_TO_HID[keycode]; +} + static LRESULT handleMessage(PuglView* view, UINT message, WPARAM wParam, LPARAM lParam) { @@ -464,9 +484,12 @@ handleMessage(PuglView* view, UINT message, WPARAM wParam, LPARAM lParam) static BYTE kbs[256]; if (GetKeyboardState(kbs) != FALSE) { char lb[2]; + + UINT keyCode = ((lParam >> 16) & 0x7f) | ((lParam & (1 << 24)) != 0 ? 0x80 : 0); UINT scanCode = (lParam >> 8) & 0xFFFFFF00; + if ( 1 == ToAscii(wParam, scanCode, kbs, (LPWORD)lb, 0)) { - view->keyboardFunc(view, message == WM_KEYDOWN, (char)lb[0]); + view->keyboardFunc(view, message == WM_KEYDOWN, (char)lb[0], keycodeToHID(keyCode)); } } } diff --git a/dgl/src/pugl/pugl_x11.c b/dgl/src/pugl/pugl_x11.c index 2783bbbf0..0f7f04607 100644 --- a/dgl/src/pugl/pugl_x11.c +++ b/dgl/src/pugl/pugl_x11.c @@ -486,6 +486,32 @@ setModifiers(PuglView* view, unsigned xstate, unsigned xtime) view->mods |= (xstate & Mod4Mask) ? PUGL_MOD_SUPER : 0; } +static unsigned +scancodeToHID(unsigned scancode) +{ + const unsigned char KEYCODE_LINUX_TO_HID[256] = { + 0,41,30,31,32,33,34,35,36,37,38,39,45,46,42,43,20,26,8,21,23,28,24,12,18,19, + 47,48,158,224,4,22,7,9,10,11,13,14,15,51,52,53,225,49,29,27,6,25,5,17,16,54, + 55,56,229,85,226,44,57,58,59,60,61,62,63,64,65,66,67,83,71,95,96,97,86,92, + 93,94,87,89,90,91,98,99,0,0,100,68,69,0,0,0,0,0,0,0,88,228,84,154,230,0,74, + 82,75,80,79,77,81,78,73,76,0,0,0,0,0,103,0,72,0,0,0,0,0,227,231,0,0,0,0,0,0, + 0,0,0,0,0,0,118,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,104,105,106,107,108,109,110,111,112,113,114,115,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + }; + + //On Linux, the keycodes are offset by KEYCODE_EVDEV_OFFSET when they are sent by evdev + const unsigned KEYCODE_EVDEV_OFFSET = 8; + + scancode -= KEYCODE_EVDEV_OFFSET; + + if (scancode >= 256) + return 0; + + return KEYCODE_LINUX_TO_HID[scancode]; +} + static void dispatchKey(PuglView* view, XEvent* event, bool press) { @@ -515,7 +541,9 @@ dispatchKey(PuglView* view, XEvent* event, bool press) return; } } else if (!special && view->keyboardFunc) { - if (view->keyboardFunc(view, press, str[0]) == 0) { + const unsigned keycode = scancodeToHID(event->xkey.keycode); + + if (view->keyboardFunc(view, press, str[0], keycode) == 0) { return; } } From 21f36962ddcb44d6232654ffd4c59325dc7d3437 Mon Sep 17 00:00:00 2001 From: Patrick Desaulniers Date: Mon, 29 Jul 2019 14:12:35 -0400 Subject: [PATCH 2/8] Better documentation for PuglKeyCodes; change keycode acronym to KC --- dgl/src/pugl/pugl.h | 252 ++++++++++++++++++++++---------------------- 1 file changed, 127 insertions(+), 125 deletions(-) diff --git a/dgl/src/pugl/pugl.h b/dgl/src/pugl/pugl.h index 238ad43e7..e02c4d92e 100644 --- a/dgl/src/pugl/pugl.h +++ b/dgl/src/pugl/pugl.h @@ -123,135 +123,137 @@ typedef enum { } PuglMod; /** - * Layout-independent keycodes. + Layout-independent keycodes. + These keycodes are relative to an US QWERTY keyboard. + Therefore, the keycode for the letter 'A' on an AZERTY keyboard will be equal to PUGL_VK_Q. */ typedef enum { /* Zero, does not correspond to any key. */ - PUGL_VK_None = 0, + PUGL_KC_None = 0, - PUGL_VK_A = 4, - PUGL_VK_B = 5, - PUGL_VK_C = 6, - PUGL_VK_D = 7, - PUGL_VK_E = 8, - PUGL_VK_F = 9, - PUGL_VK_G = 10, - PUGL_VK_H = 11, - PUGL_VK_I = 12, - PUGL_VK_J = 13, - PUGL_VK_K = 14, - PUGL_VK_L = 15, - PUGL_VK_M = 16, - PUGL_VK_N = 17, - PUGL_VK_O = 18, - PUGL_VK_P = 19, - PUGL_VK_Q = 20, - PUGL_VK_R = 21, - PUGL_VK_S = 22, - PUGL_VK_T = 23, - PUGL_VK_U = 24, - PUGL_VK_V = 25, - PUGL_VK_W = 26, - PUGL_VK_X = 27, - PUGL_VK_Y = 28, - PUGL_VK_Z = 29, - PUGL_VK_1 = 30, - PUGL_VK_2 = 31, - PUGL_VK_3 = 32, - PUGL_VK_4 = 33, - PUGL_VK_5 = 34, - PUGL_VK_6 = 35, - PUGL_VK_7 = 36, - PUGL_VK_8 = 37, - PUGL_VK_9 = 38, - PUGL_VK_0 = 39, - PUGL_VK_Escape = 41, - PUGL_VK_Delete = 42, - PUGL_VK_Tab = 43, - PUGL_VK_Space = 44, - PUGL_VK_Minus = 45, - PUGL_VK_Equals = 46, - PUGL_VK_LeftBracket = 47, - PUGL_VK_RightBracket = 48, - PUGL_VK_Backslash = 49, - PUGL_VK_Semicolon = 51, - PUGL_VK_Quote = 52, - PUGL_VK_Grave = 53, - PUGL_VK_Comma = 54, - PUGL_VK_Period = 55, - PUGL_VK_Slash = 56, - PUGL_VK_CapsLock = 57, - PUGL_VK_F1 = 58, - PUGL_VK_F2 = 59, - PUGL_VK_F3 = 60, - PUGL_VK_F4 = 61, - PUGL_VK_F5 = 62, - PUGL_VK_F6 = 63, - PUGL_VK_F7 = 64, - PUGL_VK_F8 = 65, - PUGL_VK_F9 = 66, - PUGL_VK_F10 = 67, - PUGL_VK_F11 = 68, - PUGL_VK_F12 = 69, - PUGL_VK_PrintScreen = 70, - PUGL_VK_ScrollLock = 71, - PUGL_VK_Pause = 72, - PUGL_VK_Insert = 73, - PUGL_VK_Home = 74, - PUGL_VK_PageUp = 75, - PUGL_VK_DeleteForward = 76, - PUGL_VK_End = 77, - PUGL_VK_PageDown = 78, - PUGL_VK_Right = 79, - PUGL_VK_Left = 80, - PUGL_VK_Down = 81, - PUGL_VK_Up = 82, - PUGL_VK_KP_NumLock = 83, - PUGL_VK_KP_Divide = 84, - PUGL_VK_KP_Multiply = 85, - PUGL_VK_KP_Subtract = 86, - PUGL_VK_KP_Add = 87, - PUGL_VK_KP_Enter = 88, - PUGL_VK_KP_1 = 89, - PUGL_VK_KP_2 = 90, - PUGL_VK_KP_3 = 91, - PUGL_VK_KP_4 = 92, - PUGL_VK_KP_5 = 93, - PUGL_VK_KP_6 = 94, - PUGL_VK_KP_7 = 95, - PUGL_VK_KP_8 = 96, - PUGL_VK_KP_9 = 97, - PUGL_VK_KP_0 = 98, - PUGL_VKPoint = 99, - PUGL_VK_NonUSBackslash = 100, - PUGL_VK_KP_Equals = 103, - PUGL_VK_F13 = 104, - PUGL_VK_F14 = 105, - PUGL_VK_F15 = 106, - PUGL_VK_F16 = 107, - PUGL_VK_F17 = 108, - PUGL_VK_F18 = 109, - PUGL_VK_F19 = 110, - PUGL_VK_F20 = 111, - PUGL_VK_F21 = 112, - PUGL_VK_F22 = 113, - PUGL_VK_F23 = 114, - PUGL_VK_F24 = 115, - PUGL_VK_Help = 117, - PUGL_VK_Menu = 118, - PUGL_VK_Mute = 127, - PUGL_VK_SysReq = 154, - PUGL_VK_Return = 158, - PUGL_VK_KP_Clear = 216, - PUGL_VK_KP_Decimal = 220, - PUGL_VK_LeftControl = 224, - PUGL_VK_LeftShift = 225, - PUGL_VK_LeftAlt = 226, - PUGL_VK_LeftGUI = 227, - PUGL_VK_RightControl = 228, - PUGL_VK_RightShift = 229, - PUGL_VK_RightAlt = 230, - PUGL_VK_RightGUI = 231 + PUGL_KC_A = 4, + PUGL_KC_B = 5, + PUGL_KC_C = 6, + PUGL_KC_D = 7, + PUGL_KC_E = 8, + PUGL_KC_F = 9, + PUGL_KC_G = 10, + PUGL_KC_H = 11, + PUGL_KC_I = 12, + PUGL_KC_J = 13, + PUGL_KC_K = 14, + PUGL_KC_L = 15, + PUGL_KC_M = 16, + PUGL_KC_N = 17, + PUGL_KC_O = 18, + PUGL_KC_P = 19, + PUGL_KC_Q = 20, + PUGL_KC_R = 21, + PUGL_KC_S = 22, + PUGL_KC_T = 23, + PUGL_KC_U = 24, + PUGL_KC_V = 25, + PUGL_KC_W = 26, + PUGL_KC_X = 27, + PUGL_KC_Y = 28, + PUGL_KC_Z = 29, + PUGL_KC_1 = 30, + PUGL_KC_2 = 31, + PUGL_KC_3 = 32, + PUGL_KC_4 = 33, + PUGL_KC_5 = 34, + PUGL_KC_6 = 35, + PUGL_KC_7 = 36, + PUGL_KC_8 = 37, + PUGL_KC_9 = 38, + PUGL_KC_0 = 39, + PUGL_KC_Escape = 41, + PUGL_KC_Delete = 42, + PUGL_KC_Tab = 43, + PUGL_KC_Space = 44, + PUGL_KC_Minus = 45, + PUGL_KC_Equals = 46, + PUGL_KC_LeftBracket = 47, + PUGL_KC_RightBracket = 48, + PUGL_KC_Backslash = 49, + PUGL_KC_Semicolon = 51, + PUGL_KC_Quote = 52, + PUGL_KC_Grave = 53, + PUGL_KC_Comma = 54, + PUGL_KC_Period = 55, + PUGL_KC_Slash = 56, + PUGL_KC_CapsLock = 57, + PUGL_KC_F1 = 58, + PUGL_KC_F2 = 59, + PUGL_KC_F3 = 60, + PUGL_KC_F4 = 61, + PUGL_KC_F5 = 62, + PUGL_KC_F6 = 63, + PUGL_KC_F7 = 64, + PUGL_KC_F8 = 65, + PUGL_KC_F9 = 66, + PUGL_KC_F10 = 67, + PUGL_KC_F11 = 68, + PUGL_KC_F12 = 69, + PUGL_KC_PrintScreen = 70, + PUGL_KC_ScrollLock = 71, + PUGL_KC_Pause = 72, + PUGL_KC_Insert = 73, + PUGL_KC_Home = 74, + PUGL_KC_PageUp = 75, + PUGL_KC_DeleteForward = 76, + PUGL_KC_End = 77, + PUGL_KC_PageDown = 78, + PUGL_KC_Right = 79, + PUGL_KC_Left = 80, + PUGL_KC_Down = 81, + PUGL_KC_Up = 82, + PUGL_KC_KP_NumLock = 83, + PUGL_KC_KP_Divide = 84, + PUGL_KC_KP_Multiply = 85, + PUGL_KC_KP_Subtract = 86, + PUGL_KC_KP_Add = 87, + PUGL_KC_KP_Enter = 88, + PUGL_KC_KP_1 = 89, + PUGL_KC_KP_2 = 90, + PUGL_KC_KP_3 = 91, + PUGL_KC_KP_4 = 92, + PUGL_KC_KP_5 = 93, + PUGL_KC_KP_6 = 94, + PUGL_KC_KP_7 = 95, + PUGL_KC_KP_8 = 96, + PUGL_KC_KP_9 = 97, + PUGL_KC_KP_0 = 98, + PUGL_KC_Point = 99, + PUGL_KC_NonUSBackslash = 100, + PUGL_KC_KP_Equals = 103, + PUGL_KC_F13 = 104, + PUGL_KC_F14 = 105, + PUGL_KC_F15 = 106, + PUGL_KC_F16 = 107, + PUGL_KC_F17 = 108, + PUGL_KC_F18 = 109, + PUGL_KC_F19 = 110, + PUGL_KC_F20 = 111, + PUGL_KC_F21 = 112, + PUGL_KC_F22 = 113, + PUGL_KC_F23 = 114, + PUGL_KC_F24 = 115, + PUGL_KC_Help = 117, + PUGL_KC_Menu = 118, + PUGL_KC_Mute = 127, + PUGL_KC_SysReq = 154, + PUGL_KC_Return = 158, + PUGL_KC_KP_Clear = 216, + PUGL_KC_KP_Decimal = 220, + PUGL_KC_LeftControl = 224, + PUGL_KC_LeftShift = 225, + PUGL_KC_LeftAlt = 226, + PUGL_KC_LeftGUI = 227, + PUGL_KC_RightControl = 228, + PUGL_KC_RightShift = 229, + PUGL_KC_RightAlt = 230, + PUGL_KC_RightGUI = 231 } PuglKeyCodes; /** From 5bffb9fb6340d9daecb40e9f753608abb0c79ec5 Mon Sep 17 00:00:00 2001 From: Patrick Desaulniers Date: Tue, 30 Jul 2019 08:52:45 -0400 Subject: [PATCH 3/8] Fix comment --- dgl/src/pugl/pugl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dgl/src/pugl/pugl.h b/dgl/src/pugl/pugl.h index e02c4d92e..90f516e9d 100644 --- a/dgl/src/pugl/pugl.h +++ b/dgl/src/pugl/pugl.h @@ -125,7 +125,7 @@ typedef enum { /** Layout-independent keycodes. These keycodes are relative to an US QWERTY keyboard. - Therefore, the keycode for the letter 'A' on an AZERTY keyboard will be equal to PUGL_VK_Q. + Therefore, the keycode for the letter 'A' on an AZERTY keyboard will be equal to PUGL_KC_Q. */ typedef enum { /* Zero, does not correspond to any key. */ From cb5517b550476c51f33771f4d490a58ff042d1b9 Mon Sep 17 00:00:00 2001 From: Patrick Desaulniers Date: Tue, 30 Jul 2019 09:16:23 -0400 Subject: [PATCH 4/8] Add some comments --- dgl/src/pugl/pugl_osx.m | 3 +++ dgl/src/pugl/pugl_win.cpp | 3 +++ dgl/src/pugl/pugl_x11.c | 3 +++ 3 files changed, 9 insertions(+) diff --git a/dgl/src/pugl/pugl_osx.m b/dgl/src/pugl/pugl_osx.m index ea1b16b1a..0bc54534e 100644 --- a/dgl/src/pugl/pugl_osx.m +++ b/dgl/src/pugl/pugl_osx.m @@ -121,6 +121,9 @@ - (void) setPuglTrackingArea:(NSTrackingArea *)area; return mods; } +/** + Convert system specific keycodes into system independent ones (PuglKeyCodes) +*/ static unsigned scancodeToHID(unsigned scancode) { diff --git a/dgl/src/pugl/pugl_win.cpp b/dgl/src/pugl/pugl_win.cpp index 4dd43ca92..1e03f4835 100644 --- a/dgl/src/pugl/pugl_win.cpp +++ b/dgl/src/pugl/pugl_win.cpp @@ -377,6 +377,9 @@ setModifiers(PuglView* view) view->mods |= (GetKeyState(VK_RWIN) < 0) ? PUGL_MOD_SUPER : 0; } +/** + Convert system specific keycodes into system independent ones (PuglKeyCodes) +*/ static unsigned keycodeToHID(unsigned keycode) { diff --git a/dgl/src/pugl/pugl_x11.c b/dgl/src/pugl/pugl_x11.c index 0f7f04607..e80105af5 100644 --- a/dgl/src/pugl/pugl_x11.c +++ b/dgl/src/pugl/pugl_x11.c @@ -486,6 +486,9 @@ setModifiers(PuglView* view, unsigned xstate, unsigned xtime) view->mods |= (xstate & Mod4Mask) ? PUGL_MOD_SUPER : 0; } +/** + convert system specific keycodes into system independent ones (PuglKeyCodes) + */ static unsigned scancodeToHID(unsigned scancode) { From 07c65851ba7bb19f9b64638ea3e9b8e3f41eb9cd Mon Sep 17 00:00:00 2001 From: Patrick Desaulniers Date: Mon, 26 Aug 2019 17:46:08 -0400 Subject: [PATCH 5/8] Adjustments to keycode support --- dgl/src/pugl/{COPYING => COPYING.keycode} | 0 dgl/src/pugl/pugl_osx.m | 2 +- dgl/src/pugl/pugl_win.cpp | 2 +- dgl/src/pugl/pugl_x11.c | 7 +++++-- 4 files changed, 7 insertions(+), 4 deletions(-) rename dgl/src/pugl/{COPYING => COPYING.keycode} (100%) diff --git a/dgl/src/pugl/COPYING b/dgl/src/pugl/COPYING.keycode similarity index 100% rename from dgl/src/pugl/COPYING rename to dgl/src/pugl/COPYING.keycode diff --git a/dgl/src/pugl/pugl_osx.m b/dgl/src/pugl/pugl_osx.m index 0bc54534e..5662079e3 100644 --- a/dgl/src/pugl/pugl_osx.m +++ b/dgl/src/pugl/pugl_osx.m @@ -127,7 +127,7 @@ Convert system specific keycodes into system independent ones (PuglKeyCodes) static unsigned scancodeToHID(unsigned scancode) { - const unsigned char KEYCODE_MACOS_TO_HID[128] = { + static const unsigned char KEYCODE_MACOS_TO_HID[128] = { 4,22,7,9,11,10,29,27,6,25,0,5,20,26,8,21,28,23,30,31,32,33,35,34,46,38,36, 45,37,39,48,18,24,47,12,19,158,15,13,52,14,51,49,54,56,17,16,55,43,44,53,42, 0,41,231,227,225,57,226,224,229,230,228,0,108,220,0,85,0,87,0,216,0,0,127, diff --git a/dgl/src/pugl/pugl_win.cpp b/dgl/src/pugl/pugl_win.cpp index 1e03f4835..50e039862 100644 --- a/dgl/src/pugl/pugl_win.cpp +++ b/dgl/src/pugl/pugl_win.cpp @@ -383,7 +383,7 @@ setModifiers(PuglView* view) static unsigned keycodeToHID(unsigned keycode) { - const unsigned char KEYCODE_WINDOWS_TO_HID[256] = { + static const unsigned char KEYCODE_WINDOWS_TO_HID[256] = { 0,41,30,31,32,33,34,35,36,37,38,39,45,46,42,43,20,26,8,21,23,28,24,12,18,19, 47,48,158,224,4,22,7,9,10,11,13,14,15,51,52,53,225,49,29,27,6,25,5,17,16,54, 55,56,229,0,226,0,57,58,59,60,61,62,63,64,65,66,67,72,71,0,0,0,0,0,0,0,0,0, diff --git a/dgl/src/pugl/pugl_x11.c b/dgl/src/pugl/pugl_x11.c index e80105af5..62274c259 100644 --- a/dgl/src/pugl/pugl_x11.c +++ b/dgl/src/pugl/pugl_x11.c @@ -492,7 +492,7 @@ setModifiers(PuglView* view, unsigned xstate, unsigned xtime) static unsigned scancodeToHID(unsigned scancode) { - const unsigned char KEYCODE_LINUX_TO_HID[256] = { + static const unsigned char KEYCODE_LINUX_TO_HID[256] = { 0,41,30,31,32,33,34,35,36,37,38,39,45,46,42,43,20,26,8,21,23,28,24,12,18,19, 47,48,158,224,4,22,7,9,10,11,13,14,15,51,52,53,225,49,29,27,6,25,5,17,16,54, 55,56,229,85,226,44,57,58,59,60,61,62,63,64,65,66,67,83,71,95,96,97,86,92, @@ -505,8 +505,11 @@ scancodeToHID(unsigned scancode) }; //On Linux, the keycodes are offset by KEYCODE_EVDEV_OFFSET when they are sent by evdev - const unsigned KEYCODE_EVDEV_OFFSET = 8; + static const unsigned KEYCODE_EVDEV_OFFSET = 8; + if (scancode < KEYCODE_EVDEV_OFFSET) + return 0; + scancode -= KEYCODE_EVDEV_OFFSET; if (scancode >= 256) From 86c40bc5294174d71b93dcb8ca6d2a6164797569 Mon Sep 17 00:00:00 2001 From: Patrick Desaulniers Date: Mon, 26 Aug 2019 17:59:20 -0400 Subject: [PATCH 6/8] Tweak indentation --- dgl/src/pugl/pugl.h | 256 +++++++++++++++++++------------------- dgl/src/pugl/pugl_osx.m | 20 +-- dgl/src/pugl/pugl_win.cpp | 22 ++-- dgl/src/pugl/pugl_x11.c | 30 ++--- 4 files changed, 164 insertions(+), 164 deletions(-) diff --git a/dgl/src/pugl/pugl.h b/dgl/src/pugl/pugl.h index 90f516e9d..b22a704da 100644 --- a/dgl/src/pugl/pugl.h +++ b/dgl/src/pugl/pugl.h @@ -124,136 +124,136 @@ typedef enum { /** Layout-independent keycodes. - These keycodes are relative to an US QWERTY keyboard. + These keycodes are relative to an US QWERTY keyboard. Therefore, the keycode for the letter 'A' on an AZERTY keyboard will be equal to PUGL_KC_Q. - */ +*/ typedef enum { - /* Zero, does not correspond to any key. */ - PUGL_KC_None = 0, - - PUGL_KC_A = 4, - PUGL_KC_B = 5, - PUGL_KC_C = 6, - PUGL_KC_D = 7, - PUGL_KC_E = 8, - PUGL_KC_F = 9, - PUGL_KC_G = 10, - PUGL_KC_H = 11, - PUGL_KC_I = 12, - PUGL_KC_J = 13, - PUGL_KC_K = 14, - PUGL_KC_L = 15, - PUGL_KC_M = 16, - PUGL_KC_N = 17, - PUGL_KC_O = 18, - PUGL_KC_P = 19, - PUGL_KC_Q = 20, - PUGL_KC_R = 21, - PUGL_KC_S = 22, - PUGL_KC_T = 23, - PUGL_KC_U = 24, - PUGL_KC_V = 25, - PUGL_KC_W = 26, - PUGL_KC_X = 27, - PUGL_KC_Y = 28, - PUGL_KC_Z = 29, - PUGL_KC_1 = 30, - PUGL_KC_2 = 31, - PUGL_KC_3 = 32, - PUGL_KC_4 = 33, - PUGL_KC_5 = 34, - PUGL_KC_6 = 35, - PUGL_KC_7 = 36, - PUGL_KC_8 = 37, - PUGL_KC_9 = 38, - PUGL_KC_0 = 39, - PUGL_KC_Escape = 41, - PUGL_KC_Delete = 42, - PUGL_KC_Tab = 43, - PUGL_KC_Space = 44, - PUGL_KC_Minus = 45, - PUGL_KC_Equals = 46, - PUGL_KC_LeftBracket = 47, - PUGL_KC_RightBracket = 48, - PUGL_KC_Backslash = 49, - PUGL_KC_Semicolon = 51, - PUGL_KC_Quote = 52, - PUGL_KC_Grave = 53, - PUGL_KC_Comma = 54, - PUGL_KC_Period = 55, - PUGL_KC_Slash = 56, - PUGL_KC_CapsLock = 57, - PUGL_KC_F1 = 58, - PUGL_KC_F2 = 59, - PUGL_KC_F3 = 60, - PUGL_KC_F4 = 61, - PUGL_KC_F5 = 62, - PUGL_KC_F6 = 63, - PUGL_KC_F7 = 64, - PUGL_KC_F8 = 65, - PUGL_KC_F9 = 66, - PUGL_KC_F10 = 67, - PUGL_KC_F11 = 68, - PUGL_KC_F12 = 69, - PUGL_KC_PrintScreen = 70, - PUGL_KC_ScrollLock = 71, - PUGL_KC_Pause = 72, - PUGL_KC_Insert = 73, - PUGL_KC_Home = 74, - PUGL_KC_PageUp = 75, - PUGL_KC_DeleteForward = 76, - PUGL_KC_End = 77, - PUGL_KC_PageDown = 78, - PUGL_KC_Right = 79, - PUGL_KC_Left = 80, - PUGL_KC_Down = 81, - PUGL_KC_Up = 82, - PUGL_KC_KP_NumLock = 83, - PUGL_KC_KP_Divide = 84, - PUGL_KC_KP_Multiply = 85, - PUGL_KC_KP_Subtract = 86, - PUGL_KC_KP_Add = 87, - PUGL_KC_KP_Enter = 88, - PUGL_KC_KP_1 = 89, - PUGL_KC_KP_2 = 90, - PUGL_KC_KP_3 = 91, - PUGL_KC_KP_4 = 92, - PUGL_KC_KP_5 = 93, - PUGL_KC_KP_6 = 94, - PUGL_KC_KP_7 = 95, - PUGL_KC_KP_8 = 96, - PUGL_KC_KP_9 = 97, - PUGL_KC_KP_0 = 98, - PUGL_KC_Point = 99, - PUGL_KC_NonUSBackslash = 100, - PUGL_KC_KP_Equals = 103, - PUGL_KC_F13 = 104, - PUGL_KC_F14 = 105, - PUGL_KC_F15 = 106, - PUGL_KC_F16 = 107, - PUGL_KC_F17 = 108, - PUGL_KC_F18 = 109, - PUGL_KC_F19 = 110, - PUGL_KC_F20 = 111, - PUGL_KC_F21 = 112, - PUGL_KC_F22 = 113, - PUGL_KC_F23 = 114, - PUGL_KC_F24 = 115, - PUGL_KC_Help = 117, - PUGL_KC_Menu = 118, - PUGL_KC_Mute = 127, - PUGL_KC_SysReq = 154, - PUGL_KC_Return = 158, - PUGL_KC_KP_Clear = 216, - PUGL_KC_KP_Decimal = 220, - PUGL_KC_LeftControl = 224, - PUGL_KC_LeftShift = 225, - PUGL_KC_LeftAlt = 226, - PUGL_KC_LeftGUI = 227, - PUGL_KC_RightControl = 228, - PUGL_KC_RightShift = 229, - PUGL_KC_RightAlt = 230, - PUGL_KC_RightGUI = 231 + /* Zero, does not correspond to any key. */ + PUGL_KC_None = 0, + + PUGL_KC_A = 4, + PUGL_KC_B = 5, + PUGL_KC_C = 6, + PUGL_KC_D = 7, + PUGL_KC_E = 8, + PUGL_KC_F = 9, + PUGL_KC_G = 10, + PUGL_KC_H = 11, + PUGL_KC_I = 12, + PUGL_KC_J = 13, + PUGL_KC_K = 14, + PUGL_KC_L = 15, + PUGL_KC_M = 16, + PUGL_KC_N = 17, + PUGL_KC_O = 18, + PUGL_KC_P = 19, + PUGL_KC_Q = 20, + PUGL_KC_R = 21, + PUGL_KC_S = 22, + PUGL_KC_T = 23, + PUGL_KC_U = 24, + PUGL_KC_V = 25, + PUGL_KC_W = 26, + PUGL_KC_X = 27, + PUGL_KC_Y = 28, + PUGL_KC_Z = 29, + PUGL_KC_1 = 30, + PUGL_KC_2 = 31, + PUGL_KC_3 = 32, + PUGL_KC_4 = 33, + PUGL_KC_5 = 34, + PUGL_KC_6 = 35, + PUGL_KC_7 = 36, + PUGL_KC_8 = 37, + PUGL_KC_9 = 38, + PUGL_KC_0 = 39, + PUGL_KC_Escape = 41, + PUGL_KC_Delete = 42, + PUGL_KC_Tab = 43, + PUGL_KC_Space = 44, + PUGL_KC_Minus = 45, + PUGL_KC_Equals = 46, + PUGL_KC_LeftBracket = 47, + PUGL_KC_RightBracket = 48, + PUGL_KC_Backslash = 49, + PUGL_KC_Semicolon = 51, + PUGL_KC_Quote = 52, + PUGL_KC_Grave = 53, + PUGL_KC_Comma = 54, + PUGL_KC_Period = 55, + PUGL_KC_Slash = 56, + PUGL_KC_CapsLock = 57, + PUGL_KC_F1 = 58, + PUGL_KC_F2 = 59, + PUGL_KC_F3 = 60, + PUGL_KC_F4 = 61, + PUGL_KC_F5 = 62, + PUGL_KC_F6 = 63, + PUGL_KC_F7 = 64, + PUGL_KC_F8 = 65, + PUGL_KC_F9 = 66, + PUGL_KC_F10 = 67, + PUGL_KC_F11 = 68, + PUGL_KC_F12 = 69, + PUGL_KC_PrintScreen = 70, + PUGL_KC_ScrollLock = 71, + PUGL_KC_Pause = 72, + PUGL_KC_Insert = 73, + PUGL_KC_Home = 74, + PUGL_KC_PageUp = 75, + PUGL_KC_DeleteForward = 76, + PUGL_KC_End = 77, + PUGL_KC_PageDown = 78, + PUGL_KC_Right = 79, + PUGL_KC_Left = 80, + PUGL_KC_Down = 81, + PUGL_KC_Up = 82, + PUGL_KC_KP_NumLock = 83, + PUGL_KC_KP_Divide = 84, + PUGL_KC_KP_Multiply = 85, + PUGL_KC_KP_Subtract = 86, + PUGL_KC_KP_Add = 87, + PUGL_KC_KP_Enter = 88, + PUGL_KC_KP_1 = 89, + PUGL_KC_KP_2 = 90, + PUGL_KC_KP_3 = 91, + PUGL_KC_KP_4 = 92, + PUGL_KC_KP_5 = 93, + PUGL_KC_KP_6 = 94, + PUGL_KC_KP_7 = 95, + PUGL_KC_KP_8 = 96, + PUGL_KC_KP_9 = 97, + PUGL_KC_KP_0 = 98, + PUGL_KC_Point = 99, + PUGL_KC_NonUSBackslash = 100, + PUGL_KC_KP_Equals = 103, + PUGL_KC_F13 = 104, + PUGL_KC_F14 = 105, + PUGL_KC_F15 = 106, + PUGL_KC_F16 = 107, + PUGL_KC_F17 = 108, + PUGL_KC_F18 = 109, + PUGL_KC_F19 = 110, + PUGL_KC_F20 = 111, + PUGL_KC_F21 = 112, + PUGL_KC_F22 = 113, + PUGL_KC_F23 = 114, + PUGL_KC_F24 = 115, + PUGL_KC_Help = 117, + PUGL_KC_Menu = 118, + PUGL_KC_Mute = 127, + PUGL_KC_SysReq = 154, + PUGL_KC_Return = 158, + PUGL_KC_KP_Clear = 216, + PUGL_KC_KP_Decimal = 220, + PUGL_KC_LeftControl = 224, + PUGL_KC_LeftShift = 225, + PUGL_KC_LeftAlt = 226, + PUGL_KC_LeftGUI = 227, + PUGL_KC_RightControl = 228, + PUGL_KC_RightShift = 229, + PUGL_KC_RightAlt = 230, + PUGL_KC_RightGUI = 231 } PuglKeyCodes; /** diff --git a/dgl/src/pugl/pugl_osx.m b/dgl/src/pugl/pugl_osx.m index 5662079e3..8b14cdeb5 100644 --- a/dgl/src/pugl/pugl_osx.m +++ b/dgl/src/pugl/pugl_osx.m @@ -124,22 +124,22 @@ - (void) setPuglTrackingArea:(NSTrackingArea *)area; /** Convert system specific keycodes into system independent ones (PuglKeyCodes) */ -static unsigned +static unsigned scancodeToHID(unsigned scancode) { static const unsigned char KEYCODE_MACOS_TO_HID[128] = { - 4,22,7,9,11,10,29,27,6,25,0,5,20,26,8,21,28,23,30,31,32,33,35,34,46,38,36, - 45,37,39,48,18,24,47,12,19,158,15,13,52,14,51,49,54,56,17,16,55,43,44,53,42, - 0,41,231,227,225,57,226,224,229,230,228,0,108,220,0,85,0,87,0,216,0,0,127, - 84,88,0,86,109,110,103,98,89,90,91,92,93,94,95,111,96,97,0,0,0,62,63,64,60, - 65,66,0,68,0,104,107,105,0,67,0,69,0,106,117,74,75,76,61,77,59,78,58,80,79, - 81,82,0 + 4,22,7,9,11,10,29,27,6,25,0,5,20,26,8,21,28,23,30,31,32,33,35,34,46,38,36, + 45,37,39,48,18,24,47,12,19,158,15,13,52,14,51,49,54,56,17,16,55,43,44,53,42, + 0,41,231,227,225,57,226,224,229,230,228,0,108,220,0,85,0,87,0,216,0,0,127, + 84,88,0,86,109,110,103,98,89,90,91,92,93,94,95,111,96,97,0,0,0,62,63,64,60, + 65,66,0,68,0,104,107,105,0,67,0,69,0,106,117,74,75,76,61,77,59,78,58,80,79, + 81,82,0 }; - if (scancode >= 128) - return 0; + if (scancode >= 128) + return 0; - return KEYCODE_MACOS_TO_HID[scancode]; + return KEYCODE_MACOS_TO_HID[scancode]; } static int diff --git a/dgl/src/pugl/pugl_win.cpp b/dgl/src/pugl/pugl_win.cpp index 50e039862..ba961cd79 100644 --- a/dgl/src/pugl/pugl_win.cpp +++ b/dgl/src/pugl/pugl_win.cpp @@ -384,20 +384,20 @@ static unsigned keycodeToHID(unsigned keycode) { static const unsigned char KEYCODE_WINDOWS_TO_HID[256] = { - 0,41,30,31,32,33,34,35,36,37,38,39,45,46,42,43,20,26,8,21,23,28,24,12,18,19, - 47,48,158,224,4,22,7,9,10,11,13,14,15,51,52,53,225,49,29,27,6,25,5,17,16,54, - 55,56,229,0,226,0,57,58,59,60,61,62,63,64,65,66,67,72,71,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,68,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,228,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,70,230,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,74,82,75,0,80,0,79,0,77,81,78,73,76,0,0,0,0,0,0,0,227,231, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + 0,41,30,31,32,33,34,35,36,37,38,39,45,46,42,43,20,26,8,21,23,28,24,12,18,19, + 47,48,158,224,4,22,7,9,10,11,13,14,15,51,52,53,225,49,29,27,6,25,5,17,16,54, + 55,56,229,0,226,0,57,58,59,60,61,62,63,64,65,66,67,72,71,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,68,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,228,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,70,230,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,74,82,75,0,80,0,79,0,77,81,78,73,76,0,0,0,0,0,0,0,227,231, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; - if (keycode >= 256) - return 0; + if (keycode >= 256) + return 0; - return KEYCODE_WINDOWS_TO_HID[keycode]; + return KEYCODE_WINDOWS_TO_HID[keycode]; } static LRESULT diff --git a/dgl/src/pugl/pugl_x11.c b/dgl/src/pugl/pugl_x11.c index 62274c259..1d4c40dc3 100644 --- a/dgl/src/pugl/pugl_x11.c +++ b/dgl/src/pugl/pugl_x11.c @@ -493,29 +493,29 @@ static unsigned scancodeToHID(unsigned scancode) { static const unsigned char KEYCODE_LINUX_TO_HID[256] = { - 0,41,30,31,32,33,34,35,36,37,38,39,45,46,42,43,20,26,8,21,23,28,24,12,18,19, - 47,48,158,224,4,22,7,9,10,11,13,14,15,51,52,53,225,49,29,27,6,25,5,17,16,54, - 55,56,229,85,226,44,57,58,59,60,61,62,63,64,65,66,67,83,71,95,96,97,86,92, - 93,94,87,89,90,91,98,99,0,0,100,68,69,0,0,0,0,0,0,0,88,228,84,154,230,0,74, - 82,75,80,79,77,81,78,73,76,0,0,0,0,0,103,0,72,0,0,0,0,0,227,231,0,0,0,0,0,0, - 0,0,0,0,0,0,118,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,104,105,106,107,108,109,110,111,112,113,114,115,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + 0,41,30,31,32,33,34,35,36,37,38,39,45,46,42,43,20,26,8,21,23,28,24,12,18,19, + 47,48,158,224,4,22,7,9,10,11,13,14,15,51,52,53,225,49,29,27,6,25,5,17,16,54, + 55,56,229,85,226,44,57,58,59,60,61,62,63,64,65,66,67,83,71,95,96,97,86,92, + 93,94,87,89,90,91,98,99,0,0,100,68,69,0,0,0,0,0,0,0,88,228,84,154,230,0,74, + 82,75,80,79,77,81,78,73,76,0,0,0,0,0,103,0,72,0,0,0,0,0,227,231,0,0,0,0,0,0, + 0,0,0,0,0,0,118,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,104,105,106,107,108,109,110,111,112,113,114,115,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; //On Linux, the keycodes are offset by KEYCODE_EVDEV_OFFSET when they are sent by evdev static const unsigned KEYCODE_EVDEV_OFFSET = 8; - if (scancode < KEYCODE_EVDEV_OFFSET) - return 0; - + if (scancode < KEYCODE_EVDEV_OFFSET) + return 0; + scancode -= KEYCODE_EVDEV_OFFSET; - if (scancode >= 256) - return 0; + if (scancode >= 256) + return 0; - return KEYCODE_LINUX_TO_HID[scancode]; + return KEYCODE_LINUX_TO_HID[scancode]; } static void From b34b29cf277ff068c53cf5e3730419685ca44dee Mon Sep 17 00:00:00 2001 From: Patrick Desaulniers Date: Mon, 26 Aug 2019 18:21:46 -0400 Subject: [PATCH 7/8] Expose keycodes in Base.hpp --- dgl/Base.hpp | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/dgl/Base.hpp b/dgl/Base.hpp index 903778834..0feda98aa 100644 --- a/dgl/Base.hpp +++ b/dgl/Base.hpp @@ -86,6 +86,140 @@ enum Key { kKeySuper }; +/** + Layout-independent keycodes. + These keycodes are relative to an US QWERTY keyboard. + Therefore, the keycode for the letter 'A' on an AZERTY keyboard will be equal to kKeyCodeQ. + */ +enum KeyCode { + /* Zero, does not correspond to any key. */ + kKeyCodeNone = 0, + + kKeyCodeA = 4, + kKeyCodeB = 5, + kKeyCodeC = 6, + kKeyCodeD = 7, + kKeyCodeE = 8, + kKeyCodeF = 9, + kKeyCodeG = 10, + kKeyCodeH = 11, + kKeyCodeI = 12, + kKeyCodeJ = 13, + kKeyCodeK = 14, + kKeyCodeL = 15, + kKeyCodeM = 16, + kKeyCodeN = 17, + kKeyCodeO = 18, + kKeyCodeP = 19, + kKeyCodeQ = 20, + kKeyCodeR = 21, + kKeyCodeS = 22, + kKeyCodeT = 23, + kKeyCodeU = 24, + kKeyCodeV = 25, + kKeyCodeW = 26, + kKeyCodeX = 27, + kKeyCodeY = 28, + kKeyCodeZ = 29, + kKeyCode1 = 30, + kKeyCode2 = 31, + kKeyCode3 = 32, + kKeyCode4 = 33, + kKeyCode5 = 34, + kKeyCode6 = 35, + kKeyCode7 = 36, + kKeyCode8 = 37, + kKeyCode9 = 38, + kKeyCode0 = 39, + kKeyCodeEscape = 41, + kKeyCodeDelete = 42, + kKeyCodeTab = 43, + kKeyCodeSpace = 44, + kKeyCodeMinus = 45, + kKeyCodeEquals = 46, + kKeyCodeLeftBracket = 47, + kKeyCodeRightBracket = 48, + kKeyCodeBackslash = 49, + kKeyCodeSemicolon = 51, + kKeyCodeQuote = 52, + kKeyCodeGrave = 53, + kKeyCodeComma = 54, + kKeyCodePeriod = 55, + kKeyCodeSlash = 56, + kKeyCodeCapsLock = 57, + kKeyCodeF1 = 58, + kKeyCodeF2 = 59, + kKeyCodeF3 = 60, + kKeyCodeF4 = 61, + kKeyCodeF5 = 62, + kKeyCodeF6 = 63, + kKeyCodeF7 = 64, + kKeyCodeF8 = 65, + kKeyCodeF9 = 66, + kKeyCodeF10 = 67, + kKeyCodeF11 = 68, + kKeyCodeF12 = 69, + kKeyCodePrintScreen = 70, + kKeyCodeScrollLock = 71, + kKeyCodePause = 72, + kKeyCodeInsert = 73, + kKeyCodeHome = 74, + kKeyCodePageUp = 75, + kKeyCodeDeleteForward = 76, + kKeyCodeEnd = 77, + kKeyCodePageDown = 78, + kKeyCodeRight = 79, + kKeyCodeLeft = 80, + kKeyCodeDown = 81, + kKeyCodeUp = 82, + kKeyCodeKP_NumLock = 83, + kKeyCodeKP_Divide = 84, + kKeyCodeKP_Multiply = 85, + kKeyCodeKP_Subtract = 86, + kKeyCodeKP_Add = 87, + kKeyCodeKP_Enter = 88, + kKeyCodeKP_1 = 89, + kKeyCodeKP_2 = 90, + kKeyCodeKP_3 = 91, + kKeyCodeKP_4 = 92, + kKeyCodeKP_5 = 93, + kKeyCodeKP_6 = 94, + kKeyCodeKP_7 = 95, + kKeyCodeKP_8 = 96, + kKeyCodeKP_9 = 97, + kKeyCodeKP_0 = 98, + kKeyCodePoint = 99, + kKeyCodeNonUSBackslash = 100, + kKeyCodeKP_Equals = 103, + kKeyCodeF13 = 104, + kKeyCodeF14 = 105, + kKeyCodeF15 = 106, + kKeyCodeF16 = 107, + kKeyCodeF17 = 108, + kKeyCodeF18 = 109, + kKeyCodeF19 = 110, + kKeyCodeF20 = 111, + kKeyCodeF21 = 112, + kKeyCodeF22 = 113, + kKeyCodeF23 = 114, + kKeyCodeF24 = 115, + kKeyCodeHelp = 117, + kKeyCodeMenu = 118, + kKeyCodeMute = 127, + kKeyCodeSysReq = 154, + kKeyCodeReturn = 158, + kKeyCodeKP_Clear = 216, + kKeyCodeKP_Decimal = 220, + kKeyCodeLeftControl = 224, + kKeyCodeLeftShift = 225, + kKeyCodeLeftAlt = 226, + kKeyCodeLeftGUI = 227, + kKeyCodeRightControl = 228, + kKeyCodeRightShift = 229, + kKeyCodeRightAlt = 230, + kKeyCodeRightGUI = 231 +}; + // ----------------------------------------------------------------------- // Base DGL classes From 800208423ff8cd74525e4b3987e4fd98fd661772 Mon Sep 17 00:00:00 2001 From: Patrick Desaulniers Date: Mon, 26 Aug 2019 20:26:29 -0400 Subject: [PATCH 8/8] Avoid underscores in keycode names --- dgl/Base.hpp | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/dgl/Base.hpp b/dgl/Base.hpp index 0feda98aa..931a5d36d 100644 --- a/dgl/Base.hpp +++ b/dgl/Base.hpp @@ -172,25 +172,25 @@ enum KeyCode { kKeyCodeLeft = 80, kKeyCodeDown = 81, kKeyCodeUp = 82, - kKeyCodeKP_NumLock = 83, - kKeyCodeKP_Divide = 84, - kKeyCodeKP_Multiply = 85, - kKeyCodeKP_Subtract = 86, - kKeyCodeKP_Add = 87, - kKeyCodeKP_Enter = 88, - kKeyCodeKP_1 = 89, - kKeyCodeKP_2 = 90, - kKeyCodeKP_3 = 91, - kKeyCodeKP_4 = 92, - kKeyCodeKP_5 = 93, - kKeyCodeKP_6 = 94, - kKeyCodeKP_7 = 95, - kKeyCodeKP_8 = 96, - kKeyCodeKP_9 = 97, - kKeyCodeKP_0 = 98, + kKeyCodeKPNumLock = 83, + kKeyCodeKPDivide = 84, + kKeyCodeKPMultiply = 85, + kKeyCodeKPSubtract = 86, + kKeyCodeKPAdd = 87, + kKeyCodeKPEnter = 88, + kKeyCodeKP1 = 89, + kKeyCodeKP2 = 90, + kKeyCodeKP3 = 91, + kKeyCodeKP4 = 92, + kKeyCodeKP5 = 93, + kKeyCodeKP6 = 94, + kKeyCodeKP7 = 95, + kKeyCodeKP8 = 96, + kKeyCodeKP9 = 97, + kKeyCodeKP0 = 98, kKeyCodePoint = 99, kKeyCodeNonUSBackslash = 100, - kKeyCodeKP_Equals = 103, + kKeyCodeKPEquals = 103, kKeyCodeF13 = 104, kKeyCodeF14 = 105, kKeyCodeF15 = 106, @@ -208,8 +208,8 @@ enum KeyCode { kKeyCodeMute = 127, kKeyCodeSysReq = 154, kKeyCodeReturn = 158, - kKeyCodeKP_Clear = 216, - kKeyCodeKP_Decimal = 220, + kKeyCodeKPClear = 216, + kKeyCodeKPDecimal = 220, kKeyCodeLeftControl = 224, kKeyCodeLeftShift = 225, kKeyCodeLeftAlt = 226,