Kore
Loading...
Searching...
No Matches
keyboard.h
Go to the documentation of this file.
1#pragma once
2
3#include <kinc/global.h>
4
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
13#define KINC_KEY_UNKNOWN 0
14#define KINC_KEY_BACK 1 // Android
15#define KINC_KEY_CANCEL 3
16#define KINC_KEY_HELP 6
17#define KINC_KEY_BACKSPACE 8
18#define KINC_KEY_TAB 9
19#define KINC_KEY_CLEAR 12
20#define KINC_KEY_RETURN 13
21#define KINC_KEY_SHIFT 16
22#define KINC_KEY_CONTROL 17
23#define KINC_KEY_ALT 18
24#define KINC_KEY_PAUSE 19
25#define KINC_KEY_CAPS_LOCK 20
26#define KINC_KEY_KANA 21
27#define KINC_KEY_HANGUL 21
28#define KINC_KEY_EISU 22
29#define KINC_KEY_JUNJA 23
30#define KINC_KEY_FINAL 24
31#define KINC_KEY_HANJA 25
32#define KINC_KEY_KANJI 25
33#define KINC_KEY_ESCAPE 27
34#define KINC_KEY_CONVERT 28
35#define KINC_KEY_NON_CONVERT 29
36#define KINC_KEY_ACCEPT 30
37#define KINC_KEY_MODE_CHANGE 31
38#define KINC_KEY_SPACE 32
39#define KINC_KEY_PAGE_UP 33
40#define KINC_KEY_PAGE_DOWN 34
41#define KINC_KEY_END 35
42#define KINC_KEY_HOME 36
43#define KINC_KEY_LEFT 37
44#define KINC_KEY_UP 38
45#define KINC_KEY_RIGHT 39
46#define KINC_KEY_DOWN 40
47#define KINC_KEY_SELECT 41
48#define KINC_KEY_PRINT 42
49#define KINC_KEY_EXECUTE 43
50#define KINC_KEY_PRINT_SCREEN 44
51#define KINC_KEY_INSERT 45
52#define KINC_KEY_DELETE 46
53#define KINC_KEY_0 48
54#define KINC_KEY_1 49
55#define KINC_KEY_2 50
56#define KINC_KEY_3 51
57#define KINC_KEY_4 52
58#define KINC_KEY_5 53
59#define KINC_KEY_6 54
60#define KINC_KEY_7 55
61#define KINC_KEY_8 56
62#define KINC_KEY_9 57
63#define KINC_KEY_COLON 58
64#define KINC_KEY_SEMICOLON 59
65#define KINC_KEY_LESS_THAN 60
66#define KINC_KEY_EQUALS 61
67#define KINC_KEY_GREATER_THAN 62
68#define KINC_KEY_QUESTIONMARK 63
69#define KINC_KEY_AT 64
70#define KINC_KEY_A 65
71#define KINC_KEY_B 66
72#define KINC_KEY_C 67
73#define KINC_KEY_D 68
74#define KINC_KEY_E 69
75#define KINC_KEY_F 70
76#define KINC_KEY_G 71
77#define KINC_KEY_H 72
78#define KINC_KEY_I 73
79#define KINC_KEY_J 74
80#define KINC_KEY_K 75
81#define KINC_KEY_L 76
82#define KINC_KEY_M 77
83#define KINC_KEY_N 78
84#define KINC_KEY_O 79
85#define KINC_KEY_P 80
86#define KINC_KEY_Q 81
87#define KINC_KEY_R 82
88#define KINC_KEY_S 83
89#define KINC_KEY_T 84
90#define KINC_KEY_U 85
91#define KINC_KEY_V 86
92#define KINC_KEY_W 87
93#define KINC_KEY_X 88
94#define KINC_KEY_Y 89
95#define KINC_KEY_Z 90
96#define KINC_KEY_WIN 91
97#define KINC_KEY_CONTEXT_MENU 93
98#define KINC_KEY_SLEEP 95
99#define KINC_KEY_NUMPAD_0 96
100#define KINC_KEY_NUMPAD_1 97
101#define KINC_KEY_NUMPAD_2 98
102#define KINC_KEY_NUMPAD_3 99
103#define KINC_KEY_NUMPAD_4 100
104#define KINC_KEY_NUMPAD_5 101
105#define KINC_KEY_NUMPAD_6 102
106#define KINC_KEY_NUMPAD_7 103
107#define KINC_KEY_NUMPAD_8 104
108#define KINC_KEY_NUMPAD_9 105
109#define KINC_KEY_MULTIPLY 106
110#define KINC_KEY_ADD 107
111#define KINC_KEY_SEPARATOR 108
112#define KINC_KEY_SUBTRACT 109
113#define KINC_KEY_DECIMAL 110
114#define KINC_KEY_DIVIDE 111
115#define KINC_KEY_F1 112
116#define KINC_KEY_F2 113
117#define KINC_KEY_F3 114
118#define KINC_KEY_F4 115
119#define KINC_KEY_F5 116
120#define KINC_KEY_F6 117
121#define KINC_KEY_F7 118
122#define KINC_KEY_F8 119
123#define KINC_KEY_F9 120
124#define KINC_KEY_F10 121
125#define KINC_KEY_F11 122
126#define KINC_KEY_F12 123
127#define KINC_KEY_F13 124
128#define KINC_KEY_F14 125
129#define KINC_KEY_F15 126
130#define KINC_KEY_F16 127
131#define KINC_KEY_F17 128
132#define KINC_KEY_F18 129
133#define KINC_KEY_F19 130
134#define KINC_KEY_F20 131
135#define KINC_KEY_F21 132
136#define KINC_KEY_F22 133
137#define KINC_KEY_F23 134
138#define KINC_KEY_F24 135
139#define KINC_KEY_NUM_LOCK 144
140#define KINC_KEY_SCROLL_LOCK 145
141#define KINC_KEY_WIN_OEM_FJ_JISHO 146
142#define KINC_KEY_WIN_OEM_FJ_MASSHOU 147
143#define KINC_KEY_WIN_OEM_FJ_TOUROKU 148
144#define KINC_KEY_WIN_OEM_FJ_LOYA 149
145#define KINC_KEY_WIN_OEM_FJ_ROYA 150
146#define KINC_KEY_CIRCUMFLEX 160
147#define KINC_KEY_EXCLAMATION 161
148#define KINC_KEY_DOUBLE_QUOTE 162
149#define KINC_KEY_HASH 163
150#define KINC_KEY_DOLLAR 164
151#define KINC_KEY_PERCENT 165
152#define KINC_KEY_AMPERSAND 166
153#define KINC_KEY_UNDERSCORE 167
154#define KINC_KEY_OPEN_PAREN 168
155#define KINC_KEY_CLOSE_PAREN 169
156#define KINC_KEY_ASTERISK 170
157#define KINC_KEY_PLUS 171
158#define KINC_KEY_PIPE 172
159#define KINC_KEY_HYPHEN_MINUS 173
160#define KINC_KEY_OPEN_CURLY_BRACKET 174
161#define KINC_KEY_CLOSE_CURLY_BRACKET 175
162#define KINC_KEY_TILDE 176
163#define KINC_KEY_VOLUME_MUTE 181
164#define KINC_KEY_VOLUME_DOWN 182
165#define KINC_KEY_VOLUME_UP 183
166#define KINC_KEY_COMMA 188
167#define KINC_KEY_PERIOD 190
168#define KINC_KEY_SLASH 191
169#define KINC_KEY_BACK_QUOTE 192
170#define KINC_KEY_OPEN_BRACKET 219
171#define KINC_KEY_BACK_SLASH 220
172#define KINC_KEY_CLOSE_BRACKET 221
173#define KINC_KEY_QUOTE 222
174#define KINC_KEY_META 224
175#define KINC_KEY_ALT_GR 225
176#define KINC_KEY_WIN_ICO_HELP 227
177#define KINC_KEY_WIN_ICO_00 228
178#define KINC_KEY_WIN_ICO_CLEAR 230
179#define KINC_KEY_WIN_OEM_RESET 233
180#define KINC_KEY_WIN_OEM_JUMP 234
181#define KINC_KEY_WIN_OEM_PA1 235
182#define KINC_KEY_WIN_OEM_PA2 236
183#define KINC_KEY_WIN_OEM_PA3 237
184#define KINC_KEY_WIN_OEM_WSCTRL 238
185#define KINC_KEY_WIN_OEM_CUSEL 239
186#define KINC_KEY_WIN_OEM_ATTN 240
187#define KINC_KEY_WIN_OEM_FINISH 241
188#define KINC_KEY_WIN_OEM_COPY 242
189#define KINC_KEY_WIN_OEM_AUTO 243
190#define KINC_KEY_WIN_OEM_ENLW 244
191#define KINC_KEY_WIN_OEM_BACK_TAB 245
192#define KINC_KEY_ATTN 246
193#define KINC_KEY_CRSEL 247
194#define KINC_KEY_EXSEL 248
195#define KINC_KEY_EREOF 249
196#define KINC_KEY_PLAY 250
197#define KINC_KEY_ZOOM 251
198#define KINC_KEY_PA1 253
199#define KINC_KEY_WIN_OEM_CLEAR 254
200
204KINC_FUNC void kinc_keyboard_show(void);
205
209KINC_FUNC void kinc_keyboard_hide(void);
210
215KINC_FUNC bool kinc_keyboard_active(void);
216
222KINC_FUNC void kinc_keyboard_set_key_down_callback(void (*value)(int /*key_code*/, void * /*data*/), void *data);
223
229KINC_FUNC void kinc_keyboard_set_key_up_callback(void (*value)(int /*key_code*/, void * /*data*/), void *data);
230
235KINC_FUNC void kinc_keyboard_set_key_press_callback(void (*value)(unsigned /*character*/, void * /*data*/), void *data);
236
237void kinc_internal_keyboard_trigger_key_down(int key_code);
238void kinc_internal_keyboard_trigger_key_up(int key_code);
239void kinc_internal_keyboard_trigger_key_press(unsigned character);
240
241#ifdef KINC_IMPLEMENTATION_INPUT
242#define KINC_IMPLEMENTATION
243#endif
244
245#ifdef KINC_IMPLEMENTATION
246
247#include <memory.h>
248#include <stddef.h>
249
250static void (*keyboard_key_down_callback)(int /*key_code*/, void * /*data*/) = NULL;
251static void *keyboard_key_down_callback_data = NULL;
252static void (*keyboard_key_up_callback)(int /*key_code*/, void * /*data*/) = NULL;
253static void *keyboard_key_up_callback_data = NULL;
254static void (*keyboard_key_press_callback)(unsigned /*character*/, void * /*data*/) = NULL;
255static void *keyboard_key_press_callback_data = NULL;
256
257void kinc_keyboard_set_key_down_callback(void (*value)(int /*key_code*/, void * /*data*/), void *data) {
258 keyboard_key_down_callback = value;
259 keyboard_key_down_callback_data = data;
260}
261
262void kinc_keyboard_set_key_up_callback(void (*value)(int /*key_code*/, void * /*data*/), void *data) {
263 keyboard_key_up_callback = value;
264 keyboard_key_up_callback_data = data;
265}
266
267void kinc_keyboard_set_key_press_callback(void (*value)(unsigned /*character*/, void * /*data*/), void *data) {
268 keyboard_key_press_callback = value;
269 keyboard_key_press_callback_data = data;
270}
271
272void kinc_internal_keyboard_trigger_key_down(int key_code) {
273 if (keyboard_key_down_callback != NULL) {
274 keyboard_key_down_callback(key_code, keyboard_key_down_callback_data);
275 }
276}
277
278void kinc_internal_keyboard_trigger_key_up(int key_code) {
279 if (keyboard_key_up_callback != NULL) {
280 keyboard_key_up_callback(key_code, keyboard_key_up_callback_data);
281 }
282}
283
284void kinc_internal_keyboard_trigger_key_press(unsigned character) {
285 if (keyboard_key_press_callback != NULL) {
286 keyboard_key_press_callback(character, keyboard_key_press_callback_data);
287 }
288}
289
290#endif
291
292#ifdef __cplusplus
293}
294#endif
Provides basic functionality that's used all over the place. There's usually no need to manually incl...
KINC_FUNC void kinc_keyboard_set_key_press_callback(void(*value)(unsigned, void *), void *data)
Sets the keyboard-key-press-callback which is called when the system decides that a character came in...
KINC_FUNC bool kinc_keyboard_active(void)
Figure out whether the keyboard is currently shown if the system is using a software-keyboard.
KINC_FUNC void kinc_keyboard_set_key_up_callback(void(*value)(int, void *), void *data)
Sets the keyboard-key-up-callback which is called with a key-code when a key goes up....
KINC_FUNC void kinc_keyboard_hide(void)
Hide the keyboard if the system is using a software-keyboard.
KINC_FUNC void kinc_keyboard_set_key_down_callback(void(*value)(int, void *), void *data)
Sets the keyboard-key-down-callback which is called with a key-code when a key goes down....
KINC_FUNC void kinc_keyboard_show(void)
Show the keyboard if the system is using a software-keyboard.