diff --git a/src/raylib.h b/src/raylib.h index 2a5a2f63f..d742b82c1 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1105,6 +1105,7 @@ RLAPI bool IsKeyDown(int key); // Check if a key RLAPI bool IsKeyReleased(int key); // Check if a key has been released once RLAPI bool IsKeyUp(int key); // Check if a key is NOT being pressed RLAPI void SetExitKey(int key); // Set a custom key to exit program (default is ESC) +RLAPI void SetUseRepeats(bool useRepeats); // Treat key repeats as key presses (default is false) RLAPI int GetKeyPressed(void); // Get key pressed (keycode), call it multiple times for keys queued, returns 0 when the queue is empty RLAPI int GetCharPressed(void); // Get char pressed (unicode), call it multiple times for chars queued, returns 0 when the queue is empty diff --git a/src/rcore.c b/src/rcore.c index 476ea8e2f..42c4b9f9e 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -441,6 +441,7 @@ typedef struct CoreData { int charPressedQueue[MAX_CHAR_PRESSED_QUEUE]; // Input characters queue (unicode) int charPressedQueueCount; // Input characters queue count + bool useRepeats; // If true, key repeats are treated as key presses #if defined(PLATFORM_RPI) || defined(PLATFORM_DRM) int defaultMode; // Default keyboard mode @@ -767,6 +768,7 @@ void InitWindow(int width, int height, const char *title) // Initialize global input state memset(&CORE.Input, 0, sizeof(CORE.Input)); CORE.Input.Keyboard.exitKey = KEY_ESCAPE; + CORE.Input.Keyboard.useRepeats = false; CORE.Input.Mouse.scale = (Vector2){ 1.0f, 1.0f }; CORE.Input.Mouse.cursor = MOUSE_CURSOR_ARROW; CORE.Input.Gamepad.lastButtonPressed = 0; // GAMEPAD_BUTTON_UNKNOWN @@ -3680,6 +3682,13 @@ void SetExitKey(int key) #endif } +// Treat key repeats as key presses +// NOTE: default is false +void SetUseRepeats(bool useRepeats) +{ + CORE.Input.Keyboard.useRepeats = useRepeats; +} + // NOTE: Gamepad support not implemented in emscripten GLFW3 (PLATFORM_WEB) // Check if a gamepad is available @@ -5427,7 +5436,8 @@ static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, i #endif // Check if there is space available in the key queue - if ((CORE.Input.Keyboard.keyPressedQueueCount < MAX_KEY_PRESSED_QUEUE) && (action == GLFW_PRESS)) + bool is_press = action == GLFW_PRESS || (CORE.Input.Keyboard.useRepeats && action == GLFW_REPEAT); + if ((CORE.Input.Keyboard.keyPressedQueueCount < MAX_KEY_PRESSED_QUEUE) && is_press) { // Add character to the queue CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount] = key;