Kohi Game Engine
input.h
Go to the documentation of this file.
1 
13 #pragma once
14 
15 #include "defines.h"
16 
17 struct keymap;
18 struct frame_data;
19 
23 typedef enum buttons {
32 
36 typedef enum keys {
38  KEY_BACKSPACE = 0x08,
40  KEY_ENTER = 0x0D,
42  KEY_TAB = 0x09,
44  KEY_SHIFT = 0x10,
46  KEY_CONTROL = 0x11,
47 
49  KEY_PAUSE = 0x13,
51  KEY_CAPITAL = 0x14,
52 
54  KEY_ESCAPE = 0x1B,
55 
56  KEY_CONVERT = 0x1C,
58  KEY_ACCEPT = 0x1E,
60 
62  KEY_SPACE = 0x20,
64  KEY_PAGEUP = 0x21,
66  KEY_PAGEDOWN = 0x22,
68  KEY_END = 0x23,
70  KEY_HOME = 0x24,
72  KEY_LEFT = 0x25,
74  KEY_UP = 0x26,
76  KEY_RIGHT = 0x27,
78  KEY_DOWN = 0x28,
79  KEY_SELECT = 0x29,
80  KEY_PRINT = 0x2A,
81  KEY_EXECUTE = 0x2B,
85  KEY_INSERT = 0x2D,
87  KEY_DELETE = 0x2E,
88  KEY_HELP = 0x2F,
89 
91  KEY_0 = 0x30,
93  KEY_1 = 0x31,
95  KEY_2 = 0x32,
97  KEY_3 = 0x33,
99  KEY_4 = 0x34,
101  KEY_5 = 0x35,
103  KEY_6 = 0x36,
105  KEY_7 = 0x37,
107  KEY_8 = 0x38,
109  KEY_9 = 0x39,
110 
112  KEY_A = 0x41,
114  KEY_B = 0x42,
116  KEY_C = 0x43,
118  KEY_D = 0x44,
120  KEY_E = 0x45,
122  KEY_F = 0x46,
124  KEY_G = 0x47,
126  KEY_H = 0x48,
128  KEY_I = 0x49,
130  KEY_J = 0x4A,
132  KEY_K = 0x4B,
134  KEY_L = 0x4C,
136  KEY_M = 0x4D,
138  KEY_N = 0x4E,
140  KEY_O = 0x4F,
142  KEY_P = 0x50,
144  KEY_Q = 0x51,
146  KEY_R = 0x52,
148  KEY_S = 0x53,
150  KEY_T = 0x54,
152  KEY_U = 0x55,
154  KEY_V = 0x56,
156  KEY_W = 0x57,
158  KEY_X = 0x58,
160  KEY_Y = 0x59,
162  KEY_Z = 0x5A,
163 
165  KEY_LSUPER = 0x5B,
167  KEY_RSUPER = 0x5C,
169  KEY_APPS = 0x5D,
170 
172  KEY_SLEEP = 0x5F,
173 
175  KEY_NUMPAD0 = 0x60,
177  KEY_NUMPAD1 = 0x61,
179  KEY_NUMPAD2 = 0x62,
181  KEY_NUMPAD3 = 0x63,
183  KEY_NUMPAD4 = 0x64,
185  KEY_NUMPAD5 = 0x65,
187  KEY_NUMPAD6 = 0x66,
189  KEY_NUMPAD7 = 0x67,
191  KEY_NUMPAD8 = 0x68,
193  KEY_NUMPAD9 = 0x69,
195  KEY_MULTIPLY = 0x6A,
197  KEY_ADD = 0x6B,
201  KEY_SUBTRACT = 0x6D,
203  KEY_DECIMAL = 0x6E,
205  KEY_DIVIDE = 0x6F,
206 
208  KEY_F1 = 0x70,
210  KEY_F2 = 0x71,
212  KEY_F3 = 0x72,
214  KEY_F4 = 0x73,
216  KEY_F5 = 0x74,
218  KEY_F6 = 0x75,
220  KEY_F7 = 0x76,
222  KEY_F8 = 0x77,
224  KEY_F9 = 0x78,
226  KEY_F10 = 0x79,
228  KEY_F11 = 0x7A,
230  KEY_F12 = 0x7B,
232  KEY_F13 = 0x7C,
234  KEY_F14 = 0x7D,
236  KEY_F15 = 0x7E,
238  KEY_F16 = 0x7F,
240  KEY_F17 = 0x80,
242  KEY_F18 = 0x81,
244  KEY_F19 = 0x82,
246  KEY_F20 = 0x83,
248  KEY_F21 = 0x84,
250  KEY_F22 = 0x85,
252  KEY_F23 = 0x86,
254  KEY_F24 = 0x87,
255 
257  KEY_NUMLOCK = 0x90,
258 
260  KEY_SCROLL = 0x91,
261 
264 
266  KEY_LSHIFT = 0xA0,
268  KEY_RSHIFT = 0xA1,
270  KEY_LCONTROL = 0xA2,
272  KEY_RCONTROL = 0xA3,
274  KEY_LALT = 0xA4,
276  KEY_RALT = 0xA5,
277 
280 
286  KEY_EQUAL = 0xBB,
288  KEY_COMMA = 0xBC,
290  KEY_MINUS = 0xBD,
292  KEY_PERIOD = 0xBE,
294  KEY_SLASH = 0xBF,
295 
297  KEY_GRAVE = 0xC0,
298 
300  KEY_LBRACKET = 0xDB,
302  KEY_PIPE = 0xDC,
306  KEY_RBRACKET = 0xDD,
307 
308  KEYS_MAX_KEYS = 0xFF
310 
320 b8 input_system_initialize(u64* memory_requirement, void* state, void* config);
321 
326 void input_system_shutdown(void* state);
327 
333 void input_update(const struct frame_data* p_frame_data);
334 
335 // keyboard input
336 
343 
350 
357 
364 
370 void input_process_key(keys key, b8 pressed);
371 
372 // mouse input
373 
380 
387 
394 
401 
410 
417 
424 
430 void input_process_button(buttons button, b8 pressed);
431 
437 
443 
450 KAPI const char* input_keycode_str(keys key);
451 
458 KAPI void input_keymap_push(const struct keymap* map);
459 
This file contains global type definitions which are used throughout the entire engine and applicatio...
#define KAPI
Import/export qualifier.
Definition: defines.h:177
signed char i8
Signed 8-bit integer.
Definition: defines.h:33
_Bool b8
8-bit boolean type
Definition: defines.h:58
signed int i32
Signed 32-bit integer.
Definition: defines.h:39
signed short i16
Signed 16-bit integer.
Definition: defines.h:36
unsigned long long u64
Unsigned 64-bit integer.
Definition: defines.h:28
KAPI b8 input_was_key_down(keys key)
Indicates if the given key was previously pressed down on the last frame.
KAPI b8 input_was_key_up(keys key)
Indicates if the given key was previously pressed down in the last frame.
KAPI b8 input_is_button_down(buttons button)
Indicates if the given mouse button is currently pressed.
keys
Represents available keyboard keys.
Definition: input.h:36
@ KEY_F4
The F4 key.
Definition: input.h:214
@ KEY_SPACE
The spacebar key.
Definition: input.h:62
@ KEY_UP
The up arrow key.
Definition: input.h:74
@ KEY_P
The P key.
Definition: input.h:142
@ KEY_MODECHANGE
Definition: input.h:59
@ KEY_M
The M key.
Definition: input.h:136
@ KEY_B
The B key.
Definition: input.h:114
@ KEY_SCROLL
The scroll lock key.
Definition: input.h:260
@ KEY_F9
The F9 key.
Definition: input.h:224
@ KEY_NONCONVERT
Definition: input.h:57
@ KEY_CONVERT
Definition: input.h:56
@ KEY_2
The 2 key.
Definition: input.h:95
@ KEY_F6
The F6 key.
Definition: input.h:218
@ KEY_F22
The F22 key.
Definition: input.h:250
@ KEY_NUMPAD8
The numberpad 8 key.
Definition: input.h:191
@ KEY_INSERT
The insert key.
Definition: input.h:85
@ KEY_F13
The F13 key.
Definition: input.h:232
@ KEY_SEMICOLON
The semicolon key.
Definition: input.h:279
@ KEY_ENTER
The enter key.
Definition: input.h:40
@ KEY_E
The E key.
Definition: input.h:120
@ KEY_ACCEPT
Definition: input.h:58
@ KEY_I
The I key.
Definition: input.h:128
@ KEY_W
The W key.
Definition: input.h:156
@ KEY_D
The D key.
Definition: input.h:118
@ KEY_6
The 6 key.
Definition: input.h:103
@ KEY_F7
The F7 key.
Definition: input.h:220
@ KEY_LALT
The left alt key.
Definition: input.h:274
@ KEY_1
The 1 key.
Definition: input.h:93
@ KEY_DIVIDE
The numberpad divide key.
Definition: input.h:205
@ KEY_GRAVE
The grave key.
Definition: input.h:297
@ KEY_F21
The F21 key.
Definition: input.h:248
@ KEY_ESCAPE
The Escape key.
Definition: input.h:54
@ KEY_SELECT
Definition: input.h:79
@ KEY_F10
The F10 key.
Definition: input.h:226
@ KEY_F
The F key.
Definition: input.h:122
@ KEY_H
The H key.
Definition: input.h:126
@ KEY_F24
The F24 key.
Definition: input.h:254
@ KEY_X
The X key.
Definition: input.h:158
@ KEY_PRINTSCREEN
The Print Screen key.
Definition: input.h:83
@ KEY_CONTROL
The Control/Ctrl key.
Definition: input.h:46
@ KEY_G
The G key.
Definition: input.h:124
@ KEY_SLASH
The slash key.
Definition: input.h:294
@ KEY_NUMPAD0
The numberpad 0 key.
Definition: input.h:175
@ KEY_F15
The F15 key.
Definition: input.h:236
@ KEY_PAGEDOWN
The page down key.
Definition: input.h:66
@ KEY_F17
The F17 key.
Definition: input.h:240
@ KEY_Y
The Y key.
Definition: input.h:160
@ KEY_PAGEUP
The page up key.
Definition: input.h:64
@ KEY_APPS
The applicatons key.
Definition: input.h:169
@ KEY_MINUS
The minus key.
Definition: input.h:290
@ KEY_9
The 9 key.
Definition: input.h:109
@ KEY_TAB
The tab key.
Definition: input.h:42
@ KEY_LEFT
The left arrow key.
Definition: input.h:72
@ KEY_T
The T key.
Definition: input.h:150
@ KEY_RIGHT
The right arrow key.
Definition: input.h:76
@ KEY_NUMPAD1
The numberpad 1 key.
Definition: input.h:177
@ KEY_F5
The F5 key.
Definition: input.h:216
@ KEY_NUMPAD9
The numberpad 9 key.
Definition: input.h:193
@ KEY_K
The K key.
Definition: input.h:132
@ KEY_0
The 0 key.
Definition: input.h:91
@ KEY_LSUPER
The left Windows/Super key.
Definition: input.h:165
@ KEY_NUMPAD4
The numberpad 4 key.
Definition: input.h:183
@ KEY_PERIOD
The period key.
Definition: input.h:292
@ KEY_NUMPAD2
The numberpad 2 key.
Definition: input.h:179
@ KEY_SEPARATOR
The numberpad separator key.
Definition: input.h:199
@ KEY_F14
The F14 key.
Definition: input.h:234
@ KEY_SHIFT
The shift key.
Definition: input.h:44
@ KEY_F12
The F12 key.
Definition: input.h:230
@ KEY_SLEEP
The sleep key.
Definition: input.h:172
@ KEY_F2
The F2 key.
Definition: input.h:210
@ KEY_ADD
The numberpad add key.
Definition: input.h:197
@ KEY_RALT
The right alt key.
Definition: input.h:276
@ KEY_NUMPAD5
The numberpad 5 key.
Definition: input.h:185
@ KEY_F3
The F3 key.
Definition: input.h:212
@ KEY_C
The C key.
Definition: input.h:116
@ KEY_RBRACKET
The right (square) bracket key e.g. ]}.
Definition: input.h:306
@ KEY_F8
The F8 key.
Definition: input.h:222
@ KEY_F20
The F20 key.
Definition: input.h:246
@ KEY_F19
The F19 key.
Definition: input.h:244
@ KEY_BACKSPACE
The backspace key.
Definition: input.h:38
@ KEY_R
The R key.
Definition: input.h:146
@ KEY_N
The N key.
Definition: input.h:138
@ KEY_A
The A key.
Definition: input.h:112
@ KEY_MULTIPLY
The numberpad multiply key.
Definition: input.h:195
@ KEY_END
The end key.
Definition: input.h:68
@ KEY_NUMLOCK
The number lock key.
Definition: input.h:257
@ KEY_DOWN
The down arrow key.
Definition: input.h:78
@ KEY_8
The 8 key.
Definition: input.h:107
@ KEY_F16
The F16 key.
Definition: input.h:238
@ KEY_Z
The Z key.
Definition: input.h:162
@ KEY_RSUPER
The right Windows/Super key.
Definition: input.h:167
@ KEY_F18
The F18 key.
Definition: input.h:242
@ KEY_S
The S key.
Definition: input.h:148
@ KEY_J
The J key.
Definition: input.h:130
@ KEY_LSHIFT
The left shift key.
Definition: input.h:266
@ KEY_NUMPAD6
The numberpad 6 key.
Definition: input.h:187
@ KEY_LBRACKET
The left (square) bracket key e.g. [{.
Definition: input.h:300
@ KEY_Q
The Q key.
Definition: input.h:144
@ KEY_NUMPAD_EQUAL
The numberpad equal key.
Definition: input.h:263
@ KEY_EQUAL
The equal/plus key.
Definition: input.h:286
@ KEY_QUOTE
An alias for KEY_APOSTROPHE, apostrophe/single-quote key.
Definition: input.h:284
@ KEY_LCONTROL
The left control key.
Definition: input.h:270
@ KEY_PAUSE
The pause key.
Definition: input.h:49
@ KEY_EXECUTE
Definition: input.h:81
@ KEY_U
The U key.
Definition: input.h:152
@ KEY_F11
The F11 key.
Definition: input.h:228
@ KEY_HOME
The home key.
Definition: input.h:70
@ KEY_HELP
Definition: input.h:88
@ KEY_RCONTROL
The right control key.
Definition: input.h:272
@ KEY_F23
The F23 key.
Definition: input.h:252
@ KEY_RSHIFT
The right shift key.
Definition: input.h:268
@ KEY_NUMPAD3
The numberpad 3 key.
Definition: input.h:181
@ KEY_NUMPAD7
The numberpad 7 key.
Definition: input.h:189
@ KEY_7
The 7 key.
Definition: input.h:105
@ KEY_DELETE
The delete key.
Definition: input.h:87
@ KEY_O
The O key.
Definition: input.h:140
@ KEY_PIPE
The pipe/backslash key.
Definition: input.h:302
@ KEY_4
The 4 key.
Definition: input.h:99
@ KEY_APOSTROPHE
The apostrophe/single-quote key.
Definition: input.h:282
@ KEY_L
The L key.
Definition: input.h:134
@ KEY_5
The 5 key.
Definition: input.h:101
@ KEY_3
The 3 key.
Definition: input.h:97
@ KEY_BACKSLASH
An alias for the pipe/backslash key.
Definition: input.h:304
@ KEY_SUBTRACT
The numberpad subtract key.
Definition: input.h:201
@ KEY_PRINT
Definition: input.h:80
@ KEY_COMMA
The comma key.
Definition: input.h:288
@ KEYS_MAX_KEYS
Definition: input.h:308
@ KEY_V
The V key.
Definition: input.h:154
@ KEY_CAPITAL
The Caps Lock key.
Definition: input.h:51
@ KEY_DECIMAL
The numberpad decimal key.
Definition: input.h:203
@ KEY_F1
The F1 key.
Definition: input.h:208
KAPI void input_keymap_push(const struct keymap *map)
Pushes a new keymap onto the keymap stack, making it the active keymap. A copy of the keymap is taken...
buttons
Represents available mouse buttons.
Definition: input.h:23
@ BUTTON_RIGHT
The right mouse button.
Definition: input.h:27
@ BUTTON_LEFT
The left mouse button.
Definition: input.h:25
@ BUTTON_MIDDLE
The middle mouse button (typically the wheel)
Definition: input.h:29
@ BUTTON_MAX_BUTTONS
Definition: input.h:30
KAPI void input_get_previous_mouse_position(i32 *x, i32 *y)
Obtains the previous mouse position.
void input_process_button(buttons button, b8 pressed)
Sets the press state of the given mouse button.
KAPI b8 input_is_button_up(buttons button)
Indicates if the given mouse button is currently released.
void input_process_mouse_move(i16 x, i16 y)
Sets the current position of the mouse to the given x and y positions. Also updates the previous posi...
void input_system_shutdown(void *state)
Shuts the input system down.
KAPI b8 input_is_key_down(keys key)
Indicates if the given key is currently pressed down.
KAPI b8 input_was_button_down(buttons button)
Indicates if the given mouse button was previously pressed in the last frame.
KAPI b8 input_keymap_pop(void)
Attempts to pop the top-most keymap from the stack, if there is one.
KAPI b8 input_is_key_up(keys key)
Indicates if the given key is NOT currently pressed down.
void input_process_key(keys key, b8 pressed)
Sets the state for the given key.
void input_update(const struct frame_data *p_frame_data)
Updates the input system every frame.
KAPI b8 input_is_button_dragging(buttons button)
Indicates if the mouse is currently being dragged with the provided button being held down.
KAPI const char * input_keycode_str(keys key)
Returns a string representation of the provided key. Ex. "tab" for the tab key.
KAPI b8 input_was_button_up(buttons button)
Indicates if the given mouse button was previously released in the last frame.
b8 input_system_initialize(u64 *memory_requirement, void *state, void *config)
Initializes the input system. Call twice; once to obtain memory requirement (passing state = 0),...
void input_process_mouse_wheel(i8 z_delta)
Processes mouse wheel scrolling.
KAPI void input_get_mouse_position(i32 *x, i32 *y)
Obtains the current mouse position.
Engine-level current frame-specific data.
Definition: frame_data.h:16
A keymap, which holds a list of keymap entries, each with a list of bindings. These are held in an in...
Definition: keymap.h:103