Files
game-engine/src/engine/keyboard.h
2024-04-11 01:05:03 -04:00

241 lines
7.9 KiB
C

#pragma once
#include <SDL2/SDL.h>
#include "../COMMON.h"
#define KEYBOARD_KEY_COUNT (255)
typedef enum KeyboardKeyType
{
KEYBOARD_KEY_UNKNOWN = 0,
KEYBOARD_KEY_UNKNOWN_TWO = 1,
KEYBOARD_KEY_UNKNOWN_THREE = 2,
KEYBOARD_KEY_UNKNOWN_FOUR = 3,
KEYBOARD_KEY_A = 4,
KEYBOARD_KEY_B = 5,
KEYBOARD_KEY_C = 6,
KEYBOARD_KEY_D = 7,
KEYBOARD_KEY_E = 8,
KEYBOARD_KEY_F = 9,
KEYBOARD_KEY_G = 10,
KEYBOARD_KEY_H = 11,
KEYBOARD_KEY_I = 12,
KEYBOARD_KEY_J = 13,
KEYBOARD_KEY_K = 14,
KEYBOARD_KEY_L = 15,
KEYBOARD_KEY_M = 16,
KEYBOARD_KEY_N = 17,
KEYBOARD_KEY_O = 18,
KEYBOARD_KEY_P = 19,
KEYBOARD_KEY_Q = 20,
KEYBOARD_KEY_R = 21,
KEYBOARD_KEY_S = 22,
KEYBOARD_KEY_T = 23,
KEYBOARD_KEY_U = 24,
KEYBOARD_KEY_V = 25,
KEYBOARD_KEY_W = 26,
KEYBOARD_KEY_X = 27,
KEYBOARD_KEY_Y = 28,
KEYBOARD_KEY_Z = 29,
KEYBOARD_KEY_1 = 30,
KEYBOARD_KEY_2 = 31,
KEYBOARD_KEY_3 = 32,
KEYBOARD_KEY_4 = 33,
KEYBOARD_KEY_5 = 34,
KEYBOARD_KEY_6 = 35,
KEYBOARD_KEY_7 = 36,
KEYBOARD_KEY_8 = 37,
KEYBOARD_KEY_9 = 38,
KEYBOARD_KEY_0 = 39,
KEYBOARD_KEY_RETURN = 40,
KEYBOARD_KEY_ESCAPE = 41,
KEYBOARD_KEY_BACKSPACE = 42,
KEYBOARD_KEY_TAB = 43,
KEYBOARD_KEY_SPACE = 44,
KEYBOARD_KEY_MINUS = 45,
KEYBOARD_KEY_EQUALS = 46,
KEYBOARD_KEY_LEFTBRACKET = 47,
KEYBOARD_KEY_RIGHTBRACKET = 48,
KEYBOARD_KEY_BACKSLASH = 49,
KEYBOARD_KEY_NONUSHASH = 50,
KEYBOARD_KEY_SEMICOLON = 51,
KEYBOARD_KEY_APOSTROPHE = 52,
KEYBOARD_KEY_GRAVE = 53,
KEYBOARD_KEY_COMMA = 54,
KEYBOARD_KEY_PERIOD = 55,
KEYBOARD_KEY_SLASH = 56,
KEYBOARD_KEY_CAPSLOCK = 57,
KEYBOARD_KEY_F1 = 58,
KEYBOARD_KEY_F2 = 59,
KEYBOARD_KEY_F3 = 60,
KEYBOARD_KEY_F4 = 61,
KEYBOARD_KEY_F5 = 62,
KEYBOARD_KEY_F6 = 63,
KEYBOARD_KEY_F7 = 64,
KEYBOARD_KEY_F8 = 65,
KEYBOARD_KEY_F9 = 66,
KEYBOARD_KEY_F10 = 67,
KEYBOARD_KEY_F11 = 68,
KEYBOARD_KEY_F12 = 69,
KEYBOARD_KEY_PRINTSCREEN = 70,
KEYBOARD_KEY_SCROLLLOCK = 71,
KEYBOARD_KEY_PAUSE = 72,
KEYBOARD_KEY_INSERT = 73,
KEYBOARD_KEY_HOME = 74,
KEYBOARD_KEY_PAGEUP = 75,
KEYBOARD_KEY_DELETE = 76,
KEYBOARD_KEY_END = 77,
KEYBOARD_KEY_PAGEDOWN = 78,
KEYBOARD_KEY_RIGHT = 79,
KEYBOARD_KEY_LEFT = 80,
KEYBOARD_KEY_DOWN = 81,
KEYBOARD_KEY_UP = 82,
KEYBOARD_KEY_NUMLOCKCLEAR = 83,
KEYBOARD_KEY_KP_DIVIDE = 84,
KEYBOARD_KEY_KP_MULTIPLY = 85,
KEYBOARD_KEY_KP_MINUS = 86,
KEYBOARD_KEY_KP_PLUS = 87,
KEYBOARD_KEY_KP_ENTER = 88,
KEYBOARD_KEY_KP_1 = 89,
KEYBOARD_KEY_KP_2 = 90,
KEYBOARD_KEY_KP_3 = 91,
KEYBOARD_KEY_KP_4 = 92,
KEYBOARD_KEY_KP_5 = 93,
KEYBOARD_KEY_KP_6 = 94,
KEYBOARD_KEY_KP_7 = 95,
KEYBOARD_KEY_KP_8 = 96,
KEYBOARD_KEY_KP_9 = 97,
KEYBOARD_KEY_KP_0 = 98,
KEYBOARD_KEY_KP_PERIOD = 99,
KEYBOARD_KEY_NONUSBACKSLASH = 100,
KEYBOARD_KEY_APPLICATION = 101,
KEYBOARD_KEY_POWER = 102,
KEYBOARD_KEY_KP_EQUALS = 103,
KEYBOARD_KEY_F13 = 104,
KEYBOARD_KEY_F14 = 105,
KEYBOARD_KEY_F15 = 106,
KEYBOARD_KEY_F16 = 107,
KEYBOARD_KEY_F17 = 108,
KEYBOARD_KEY_F18 = 109,
KEYBOARD_KEY_F19 = 110,
KEYBOARD_KEY_F20 = 111,
KEYBOARD_KEY_F21 = 112,
KEYBOARD_KEY_F22 = 113,
KEYBOARD_KEY_F23 = 114,
KEYBOARD_KEY_F24 = 115,
KEYBOARD_KEY_EXECUTE = 116,
KEYBOARD_KEY_HELP = 117,
KEYBOARD_KEY_MENU = 118,
KEYBOARD_KEY_SELECT = 119,
KEYBOARD_KEY_STOP = 120,
KEYBOARD_KEY_AGAIN = 121,
KEYBOARD_KEY_UNDO = 122,
KEYBOARD_KEY_CUT = 123,
KEYBOARD_KEY_COPY = 124,
KEYBOARD_KEY_PASTE = 125,
KEYBOARD_KEY_FIND = 126,
KEYBOARD_KEY_MUTE = 127,
KEYBOARD_KEY_VOLUMEUP = 128,
KEYBOARD_KEY_VOLUMEDOWN = 129,
KEYBOARD_KEY_LOCKINGCAPSLOCK = 130,
KEYBOARD_KEY_LOCKINGNUMLOCK = 131,
KEYBOARD_KEY_LOCKINGSCROLLLOCK = 132,
KEYBOARD_KEY_KP_COMMA = 133,
KEYBOARD_KEY_KP_EQUALSAS400 = 134,
KEYBOARD_KEY_INTERNATIONAL1 = 135,
KEYBOARD_KEY_INTERNATIONAL2 = 136,
KEYBOARD_KEY_INTERNATIONAL3 = 137,
KEYBOARD_KEY_INTERNATIONAL4 = 138,
KEYBOARD_KEY_INTERNATIONAL5 = 139,
KEYBOARD_KEY_INTERNATIONAL6 = 140,
KEYBOARD_KEY_INTERNATIONAL7 = 141,
KEYBOARD_KEY_INTERNATIONAL8 = 142,
KEYBOARD_KEY_INTERNATIONAL9 = 143,
KEYBOARD_KEY_LANG1 = 144,
KEYBOARD_KEY_LANG2 = 145,
KEYBOARD_KEY_LANG3 = 146,
KEYBOARD_KEY_LANG4 = 147,
KEYBOARD_KEY_LANG5 = 148,
KEYBOARD_KEY_LANG6 = 149,
KEYBOARD_KEY_LANG7 = 150,
KEYBOARD_KEY_LANG8 = 151,
KEYBOARD_KEY_LANG9 = 152,
KEYBOARD_KEY_ALTERASE = 153,
KEYBOARD_KEY_SYSREQ = 154,
KEYBOARD_KEY_CANCEL = 155,
KEYBOARD_KEY_CLEAR = 156,
KEYBOARD_KEY_PRIOR = 157,
KEYBOARD_KEY_RETURN2 = 158,
KEYBOARD_KEY_SEPARATOR = 159,
KEYBOARD_KEY_OUT = 160,
KEYBOARD_KEY_OPER = 161,
KEYBOARD_KEY_CLEARAGAIN = 162,
KEYBOARD_KEY_CRSEL = 163,
KEYBOARD_KEY_EXSEL = 164,
KEYBOARD_KEY_KP_00 = 176,
KEYBOARD_KEY_KP_000 = 177,
KEYBOARD_KEY_THOUSANDSSEPARATOR = 178,
KEYBOARD_KEY_DECIMALSEPARATOR = 179,
KEYBOARD_KEY_CURRENCYUNIT = 180,
KEYBOARD_KEY_CURRENCYSUBUNIT = 181,
KEYBOARD_KEY_KP_LEFTPAREN = 182,
KEYBOARD_KEY_KP_RIGHTPAREN = 183,
KEYBOARD_KEY_KP_LEFTBRACE = 184,
KEYBOARD_KEY_KP_RIGHTBRACE = 185,
KEYBOARD_KEY_KP_TAB = 186,
KEYBOARD_KEY_KP_BACKSPACE = 187,
KEYBOARD_KEY_KP_A = 188,
KEYBOARD_KEY_KP_B = 189,
KEYBOARD_KEY_KP_C = 190,
KEYBOARD_KEY_KP_D = 191,
KEYBOARD_KEY_KP_E = 192,
KEYBOARD_KEY_KP_F = 193,
KEYBOARD_KEY_KP_XOR = 194,
KEYBOARD_KEY_KP_POWER = 195,
KEYBOARD_KEY_KP_PERCENT = 196,
KEYBOARD_KEY_KP_LESS = 197,
KEYBOARD_KEY_KP_GREATER = 198,
KEYBOARD_KEY_KP_AMPERSAND = 199,
KEYBOARD_KEY_KP_DBLAMPERSAND = 200,
KEYBOARD_KEY_KP_VERTICALBAR = 201,
KEYBOARD_KEY_KP_DBLVERTICALBAR = 202,
KEYBOARD_KEY_KP_COLON = 203,
KEYBOARD_KEY_KP_HASH = 204,
KEYBOARD_KEY_KP_SPACE = 205,
KEYBOARD_KEY_KP_AT = 206,
KEYBOARD_KEY_KP_EXCLAM = 207,
KEYBOARD_KEY_KP_MEMSTORE = 208,
KEYBOARD_KEY_KP_MEMRECALL = 209,
KEYBOARD_KEY_KP_MEMCLEAR = 210,
KEYBOARD_KEY_KP_MEMADD = 211,
KEYBOARD_KEY_KP_MEMSUBTRACT = 212,
KEYBOARD_KEY_KP_MEMMULTIPLY = 213,
KEYBOARD_KEY_KP_MEMDIVIDE = 214,
KEYBOARD_KEY_KP_PLUSMINUS = 215,
KEYBOARD_KEY_KP_CLEAR = 216,
KEYBOARD_KEY_KP_CLEARENTRY = 217,
KEYBOARD_KEY_KP_BINARY = 218,
KEYBOARD_KEY_KP_OCTAL = 219,
KEYBOARD_KEY_KP_DECIMAL = 220,
KEYBOARD_KEY_KP_HEXADECIMAL = 221,
KEYBOARD_KEY_LCTRL = 224,
KEYBOARD_KEY_LSHIFT = 225,
KEYBOARD_KEY_LALT = 226,
KEYBOARD_KEY_LGUI = 227,
KEYBOARD_KEY_RCTRL = 228,
KEYBOARD_KEY_RSHIFT = 229,
KEYBOARD_KEY_RALT = 230,
KEYBOARD_KEY_RGUI = 231
} KeyboardKeyType;
typedef struct Keyboard
{
u8 current[KEYBOARD_KEY_COUNT];
u8 previous[KEYBOARD_KEY_COUNT];
} Keyboard;
void keyboard_update(Keyboard* self);
bool keyboard_press(Keyboard* self, KeyboardKeyType type);
bool keyboard_held(Keyboard* self, KeyboardKeyType type);
bool keyboard_release(Keyboard* self, KeyboardKeyType type);