From 6ee5718b2e65c69fca695fdf999fa1838c63aa0b Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sun, 6 Mar 2016 19:30:16 +0100 Subject: [PATCH] Improved function GetKeyPressed() To support multiple keys (including function keys) --- src/core.c | 9 +++++---- src/raygui.c | 17 ++++++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/core.c b/src/core.c index 870ca3b4a..6b2321c29 100644 --- a/src/core.c +++ b/src/core.c @@ -1735,10 +1735,11 @@ static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, i TakeScreenshot(); } #endif - else currentKeyState[key] = action; - - // TODO: Review (and remove) this HACK for GuiTextBox, to deteck back key - if ((key == 259) && (action == GLFW_PRESS)) lastKeyPressed = 3; + else + { + currentKeyState[key] = action; + if (action == GLFW_PRESS) lastKeyPressed = key; + } } // GLFW3 Mouse Button Callback, runs on mouse button pressed diff --git a/src/raygui.c b/src/raygui.c index 3d7a67ecb..e66c33b58 100644 --- a/src/raygui.c +++ b/src/raygui.c @@ -789,11 +789,11 @@ int GuiSpinner(Rectangle bounds, int value, int minValue, int maxValue) // NOTE: Requires static variables: framesCounter - ERROR! char *GuiTextBox(Rectangle bounds, char *text) { - #define MAX_CHARS_LENGTH 20 - #define KEY_BACKSPACE_TEXT 3 + #define MAX_CHARS_LENGTH 20 + #define KEY_BACKSPACE_TEXT 259 // GLFW BACKSPACE: 3 + 256 int initPos = bounds.x + 4; - char letter = -1; + int letter = -1; static int framesCounter = 0; Vector2 mousePoint = GetMousePosition(); @@ -822,12 +822,15 @@ char *GuiTextBox(Rectangle bounds, char *text) } else { - for (int i = 0; i < MAX_CHARS_LENGTH; i++) + if ((letter >= 32) && (letter < 127)) { - if (text[i] == '\0') + for (int i = 0; i < MAX_CHARS_LENGTH; i++) { - text[i] = letter; - break; + if (text[i] == '\0') + { + text[i] = (char)letter; + break; + } } } }