µGFX  2.9
version 2.9
ginput_keyboard.h
Go to the documentation of this file.
1 /*
2  * This file is subject to the terms of the GFX License. If a copy of
3  * the license was not distributed with this file, you can obtain one at:
4  *
5  * http://ugfx.io/license.html
6  */
7 
8 /**
9  * @file src/ginput/ginput_keyboard.h
10  *
11  * @defgroup Keyboard Keyboard
12  * @ingroup GINPUT
13  *
14  * @brief Sub-Module to handle physical keyboards.
15  *
16  * @{
17  */
18 
19 #ifndef _GINPUT_KEYBOARD_H
20 #define _GINPUT_KEYBOARD_H
21 
22 #if GINPUT_NEED_KEYBOARD || GWIN_NEED_KEYBOARD || defined(__DOXYGEN__)
23 
24 /*===========================================================================*/
25 /* Type definitions */
26 /*===========================================================================*/
27 
28 // Event types for various ginput sources
29 #define GEVENT_KEYBOARD (GEVENT_GINPUT_FIRST+2)
30 
31 typedef struct GEventKeyboard_t {
32  GEventType type; // The type of this event (GEVENT_KEYBOARD)
33  gU16 bytecount; // The number of bytes in c[]. Note this will only ever represent 0 or 1 characters. This is set to 0 for state transitions.
34  char c[8]; // The utf8 code for the key or a special key code
35  // Normal characters with special meaning. They are a maximum of 1 byte in length.
36  #define GKEY_NULL 0
37  #define GKEY_BACKSPACE 8
38  #define GKEY_TAB 9
39  #define GKEY_LF 10
40  #define GKEY_CR 13
41  #define GKEY_ENTER 13
42  #define GKEY_ESC 27
43  #define GKEY_SPACE 32
44  #define GKEY_DEL 127
45 
46  // These are special keys - GKEYSTATE_SPECIAL will be set. They are a maximum of 1 byte in length.
47  #define GKEY_UP 0x81
48  #define GKEY_DOWN 0x82
49  #define GKEY_LEFT 0x83
50  #define GKEY_RIGHT 0x84
51  #define GKEY_HOME 0x85
52  #define GKEY_END 0x86
53  #define GKEY_PAGEUP 0x87
54  #define GKEY_PAGEDOWN 0x88
55  #define GKEY_INSERT 0x89
56  #define GKEY_WINKEY 0x8A
57  #define GKEY_RIGHTCLICKKEY 0x8B
58  #define GKEY_FN1 0x91
59  #define GKEY_FN2 0x92
60  #define GKEY_FN3 0x93
61  #define GKEY_FN4 0x94
62  #define GKEY_FN5 0x95
63  #define GKEY_FN6 0x96
64  #define GKEY_FN7 0x97
65  #define GKEY_FN8 0x98
66  #define GKEY_FN9 0x99
67  #define GKEY_FN10 0x9A
68  #define GKEY_FN11 0x9B
69  #define GKEY_FN12 0x9C
70  #define GKEY_FN13 0x9D
71  #define GKEY_FN14 0x9E
72  #define GKEY_FN15 0x9F
73  #define GKEY_CTRLBREAK 0xA0
74  #define GKEY_CTRLPAUSE 0xA1
75  #define GKEY_SYSREQ 0xA2
76  #define GKEY_PRINTSCREEN 0xA3
77  #define GKEY_POWER 0xA4
78  #define GKEY_SLEEP 0xA5
79  #define GKEY_SCREENSWITCH 0xA6
80  #define GKEY_SCREENLOCK 0xA7
81  #define GKEY_WIFIONOFF 0xA8
82  #define GKEY_TRACKPADONOFF 0xA9
83  #define GKEY_STARTMEDIA 0xAA
84  #define GKEY_STARTHOME 0xAB
85  #define GKEY_STARTEMAIL 0xAC
86  #define GKEY_STARTCOMPUTER 0xAD
87  #define GKEY_STARTAPP1 0xAE
88  #define GKEY_STARTAPP2 0xAF
89  #define GKEY_VOLUP 0xB0
90  #define GKEY_VOLDOWN 0xB1
91  #define GKEY_VOLMUTE 0xB2
92  #define GKEY_EJECT 0xB3
93  #define GKEY_MEDIAPLAY 0xB4
94  #define GKEY_MEDIASTOP 0xB5
95  #define GKEY_MEDIAPAUSE 0xB6
96  #define GKEY_MEDIAFORWARD 0xB7
97  #define GKEY_MEDIANEXT 0xB8
98  #define GKEY_MEDIAREWIND 0xB9
99  #define GKEY_MEDIAPREV 0xBA
100  #define GKEY_MEDIASLOW 0xBB
101  #define GKEY_LIGHTUP 0xBC
102  #define GKEY_LIGHTDOWN 0xBD
103  #define GKEY_LIGHTONOFF 0xBE
104  #define GKEY_LAYOUT_FIRST 0xC0 // Special characters the layout can return start here.
105  #define GKEY_DRIVER_FIRST 0xE0 // Special characters the driver can return start here.
106 
107  gU32 keystate; // The keyboard state.
108  #define GKEYSTATE_KEYUP_BIT 0
109  #define GKEYSTATE_REPEAT_BIT 1
110  #define GKEYSTATE_SPECIAL_BIT 2
111  #define GKEYSTATE_RAW_BIT 3
112  #define GKEYSTATE_SHIFT_L_BIT 4
113  #define GKEYSTATE_SHIFT_R_BIT 5
114  #define GKEYSTATE_CTRL_L_BIT 6
115  #define GKEYSTATE_CTRL_R_BIT 7
116  #define GKEYSTATE_ALT_L_BIT 8
117  #define GKEYSTATE_ALT_R_BIT 9
118  #define GKEYSTATE_FN_BIT 10
119  #define GKEYSTATE_COMPOSE_BIT 11
120  #define GKEYSTATE_WINKEY_BIT 12
121  #define GKEYSTATE_CAPSLOCK_BIT 13
122  #define GKEYSTATE_NUMLOCK_BIT 14
123  #define GKEYSTATE_SCROLLLOCK_BIT 15
124  #define GKEYSTATE_LAYOUT_FIRST_BIT 16
125  #define GKEYSTATE_SYSTEM_FIRST_BIT 20
126  #define GKEYSTATE_DRIVER_FIRST_BIT 24
127  #define GKEYSTATE_MISSED_EVENT_BIT 31
128 
129  #define GKEYSTATE_KEYUP (1<<GKEYSTATE_KEYUP_BIT) // This is a keyup rather than a keydown event
130  #define GKEYSTATE_REPEAT (1<<GKEYSTATE_REPEAT_BIT) // This is an automatic repeat character
131  #define GKEYSTATE_SPECIAL (1<<GKEYSTATE_SPECIAL_BIT) // The character is a special character defined above and not a normal (utf8) character
132  #define GKEYSTATE_RAW (1<<GKEYSTATE_RAW_BIT) // The character is a raw scancode and not a normal character
133  #define GKEYSTATE_SHIFT_L (1<<GKEYSTATE_SHIFT_L_BIT) // Left Shift is down
134  #define GKEYSTATE_SHIFT_R (1<<GKEYSTATE_SHIFT_R_BIT) // Right Shift is down
135  #define GKEYSTATE_CTRL_L (1<<GKEYSTATE_CTRL_L_BIT) // Left Control is down
136  #define GKEYSTATE_CTRL_R (1<<GKEYSTATE_CTRL_R_BIT) // Right Control is down
137  #define GKEYSTATE_APPLE_CMD_L (1<<GKEYSTATE_CTRL_L_BIT) // Left Cmd (apple keyboard) is down
138  #define GKEYSTATE_APPLE_CMD_R (1<<GKEYSTATE_CTRL_R_BIT) // Right Cmd (apple keyboard) is down
139  #define GKEYSTATE_ALT_L (1<<GKEYSTATE_ALT_L_BIT) // Left Alt is down
140  #define GKEYSTATE_ALT_R (1<<GKEYSTATE_ALT_R_BIT) // Right Alt is down
141  #define GKEYSTATE_APPLE_OPTION_L (1<<GKEYSTATE_ALT_L_BIT) // Left Option (apple keyboard) is down
142  #define GKEYSTATE_APPLE_OPTION_R (1<<GKEYSTATE_ALT_R_BIT) // Right Option (apple keyboard) is down
143  #define GKEYSTATE_FN (1<<GKEYSTATE_FN_BIT) // Fn is down
144  #define GKEYSTATE_COMPOSE (1<<GKEYSTATE_COMPOSE_BIT) // Compose is down
145  #define GKEYSTATE_WINKEY (1<<GKEYSTATE_WINKEY_BIT) // WinKey is down
146  #define GKEYSTATE_APPLE_CTRL (1<<GKEYSTATE_WINKEY_BIT) // Control key on apple keyboard is down
147  #define GKEYSTATE_CAPSLOCK (1<<GKEYSTATE_CAPSLOCK_BIT) // CapsLock is on
148  #define GKEYSTATE_NUMLOCK (1<<GKEYSTATE_NUMLOCK_BIT) // NumLock is on
149  #define GKEYSTATE_SCROLLLOCK (1<<GKEYSTATE_SCROLLLOCK_BIT) // ScrollLock is on
150  #define GKEYSTATE_LAYOUT_FIRST (1<<GKEYSTATE_LAYOUT_FIRST_BIT) // 4 bits for extra states for the key Layout
151  #define GKEYSTATE_SYSTEM_FIRST (1<<GKEYSTATE_SYSTEM_FIRST_BIT) // 1st available flag for the system's use (maximum 4 bits)
152  #define GKEYSTATE_DRIVER_FIRST (1<<GKEYSTATE_DRIVER_FIRST_BIT) // 1st available flag for the driver's use (maximum 7 bits)
153  #define GKEYSTATE_MISSED_EVENT (1<<GKEYSTATE_MISSED_EVENT_BIT) // A keyboard event has been missed
154 
155  #define GKEYSTATE_SHIFT (GKEYSTATE_SHIFT_L|GKEYSTATE_SHIFT_R) // A shift key is down (left or right)
156  #define GKEYSTATE_CTRL (GKEYSTATE_CTRL_L|GKEYSTATE_CTRL_R) // A control key is down (left or right)
157  #define GKEYSTATE_ALT (GKEYSTATE_ALT_L|GKEYSTATE_ALT_R) // A alt key is down (left or right)
158  #define GKEYSTATE_APPLE_OPTION (GKEYSTATE_APPLE_OPTION_L|GKEYSTATE_APPLE_OPTION_R) // A apple option key is down (left or right)
159  #define GKEYSTATE_APPLE_CMD (GKEYSTATE_APPLE_CMD_L|GKEYSTATE_APPLE_CMD_R) // A apple cmd key is down (left or right)
160 } GEventKeyboard;
161 
162 // Keyboard Listen Flags - passed to geventAddSourceToListener()
163 #define GLISTEN_KEYREPEATSOFF 0x0001 // Ignore key repeats (if possible)
164 #define GLISTEN_KEYNOSPECIALS 0x0002 // Ignore special keys
165 #define GLISTEN_KEYUP 0x0004 // Return keyup's as well as key down events
166 #define GLISTEN_KEYTRANSITIONS 0x0008 // Return transitions to the key state
167 #define GLISTEN_KEYRAW 0x0010 // Return raw scan-codes. This turns off normal character processing.
168 
169 // All keyboards
170 #define GKEYBOARD_ALL_INSTANCES ((unsigned)-1)
171 
172 #endif
173 
174 /*===========================================================================*/
175 /* External declarations. */
176 /*===========================================================================*/
177 
178 /**
179  * @brief Create a keyboard input instance
180  *
181  * @param[in] instance The ID of the keyboard input instance (from 0 to 9999)
182  *
183  * @return The source handle of the created input instance
184  */
185 GSourceHandle ginputGetKeyboard(unsigned instance);
186 
187 #if GINPUT_NEED_KEYBOARD || defined(__DOXYGEN__)
188 
189  /**
190  * @brief Get the current keyboard status
191  *
192  * @param[in] instance The ID of the keyboard input instance
193  * @param[in] pkeyboard The keyboard event struct
194  *
195  * @return Returns gFalse on an error (eg invalid instance)
196  */
197  gBool ginputGetKeyboardStatus(unsigned instance, GEventKeyboard *pkeyboard);
198 
199  #if !GKEYBOARD_LAYOUT_OFF || defined(__DOXYGEN__)
200  /**
201  * @brief Set the keyboard layout
202  *
203  * @param[in] instance The ID of the keyboard input instance
204  * @param[in] pLayout The keyboard layout micro-code. Passing NULL defaults to the driver's default layout.
205  *
206  * @return Returns gFalse on an error (eg invalid instance)
207  */
208  gBool ginputSetKeyboardLayout(unsigned instance, const void *pLayout);
209  #endif
210 #endif /* GINPUT_NEED_KEYBOARD */
211 
212 #endif /* _GINPUT_KEYBOARD_H */
213 /** @} */
gBool ginputSetKeyboardLayout(unsigned instance, const void *pLayout)
Set the keyboard layout.
GSourceHandle ginputGetKeyboard(unsigned instance)
Create a keyboard input instance.
gBool ginputGetKeyboardStatus(unsigned instance, GEventKeyboard *pkeyboard)
Get the current keyboard status.