Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keycodes support #156

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 134 additions & 0 deletions dgl/Base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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,
kKeyCodeKPEquals = 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,
kKeyCodeKPClear = 216,
kKeyCodeKPDecimal = 220,
kKeyCodeLeftControl = 224,
kKeyCodeLeftShift = 225,
kKeyCodeLeftAlt = 226,
kKeyCodeLeftGUI = 227,
kKeyCodeRightControl = 228,
kKeyCodeRightShift = 229,
kKeyCodeRightAlt = 230,
kKeyCodeRightGUI = 231
};

// -----------------------------------------------------------------------
// Base DGL classes

Expand Down
1 change: 1 addition & 0 deletions dgl/Widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class Widget
struct KeyboardEvent : BaseEvent {
bool press;
uint key;
uint keycode;

/** Constuctor */
KeyboardEvent() noexcept
Expand Down
7 changes: 4 additions & 3 deletions dgl/src/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -818,6 +818,7 @@ struct Window::PrivateData {
Widget::KeyboardEvent ev;
ev.press = press;
ev.key = key;
ev.keycode = keycode;
ev.mod = static_cast<Modifier>(puglGetModifiers(fView));
ev.time = puglGetEventTimestamp(fView);

Expand Down Expand Up @@ -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)
Expand Down
23 changes: 23 additions & 0 deletions dgl/src/pugl/COPYING.keycode
Original file line number Diff line number Diff line change
@@ -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 <depp@zdome.net>

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.
136 changes: 135 additions & 1 deletion dgl/src/pugl/pugl.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,140 @@ typedef enum {
PUGL_MOD_SUPER = 1 << 3 /**< Mod4/Command/Windows key */
} PuglMod;

/**
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_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
} PuglKeyCodes;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to expose this outside of pugl too. Otherwise, the users will have to include pugl.h to use these keycodes.


/**
Handle for opaque user data.
*/
Expand All @@ -144,7 +278,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.
Expand Down
Loading