From 32897d35fa724e46e4195927d385da4e35ac7c76 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Thu, 8 Feb 2024 07:55:30 -0800 Subject: Add function to check for key press. --- gfx-app/src/gfx_app.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'gfx-app/src/gfx_app.c') diff --git a/gfx-app/src/gfx_app.c b/gfx-app/src/gfx_app.c index a313ce8..e0211b1 100644 --- a/gfx-app/src/gfx_app.c +++ b/gfx-app/src/gfx_app.c @@ -138,3 +138,66 @@ cleanup: void gfx_app_get_mouse_position(double* x, double* y) { glfwGetCursorPos(g_gfx_app.window, x, y); } + +static int to_glfw_key(Key key); + +bool gfx_is_key_pressed(Key key) { + return glfwGetKey(g_gfx_app.window, to_glfw_key(key)) == GLFW_PRESS; +} + +static int to_glfw_key(Key key) { + switch (key) { + case KeyA: + return GLFW_KEY_A; + case KeyB: + return GLFW_KEY_B; + case KeyC: + return GLFW_KEY_C; + case KeyD: + return GLFW_KEY_D; + case KeyE: + return GLFW_KEY_E; + case KeyF: + return GLFW_KEY_F; + case KeyG: + return GLFW_KEY_G; + case KeyH: + return GLFW_KEY_H; + case KeyI: + return GLFW_KEY_I; + case KeyJ: + return GLFW_KEY_J; + case KeyK: + return GLFW_KEY_K; + case KeyL: + return GLFW_KEY_L; + case KeyM: + return GLFW_KEY_M; + case KeyN: + return GLFW_KEY_N; + case KeyO: + return GLFW_KEY_O; + case KeyP: + return GLFW_KEY_P; + case KeyQ: + return GLFW_KEY_Q; + case KeyR: + return GLFW_KEY_R; + case KeyS: + return GLFW_KEY_S; + case KeyT: + return GLFW_KEY_T; + case KeyU: + return GLFW_KEY_U; + case KeyV: + return GLFW_KEY_V; + case KeyW: + return GLFW_KEY_W; + case KeyX: + return GLFW_KEY_X; + case KeyY: + return GLFW_KEY_Y; + case KeyZ: + return GLFW_KEY_Z; + } +} -- cgit v1.2.3