Add option to process key repeats as presses (#2041)
This commit is contained in:
parent
5978358e58
commit
683a0a990b
|
|
@ -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 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 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 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 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
|
RLAPI int GetCharPressed(void); // Get char pressed (unicode), call it multiple times for chars queued, returns 0 when the queue is empty
|
||||||
|
|
||||||
|
|
|
||||||
12
src/rcore.c
12
src/rcore.c
|
|
@ -441,6 +441,7 @@ typedef struct CoreData {
|
||||||
|
|
||||||
int charPressedQueue[MAX_CHAR_PRESSED_QUEUE]; // Input characters queue (unicode)
|
int charPressedQueue[MAX_CHAR_PRESSED_QUEUE]; // Input characters queue (unicode)
|
||||||
int charPressedQueueCount; // Input characters queue count
|
int charPressedQueueCount; // Input characters queue count
|
||||||
|
bool useRepeats; // If true, key repeats are treated as key presses
|
||||||
|
|
||||||
#if defined(PLATFORM_RPI) || defined(PLATFORM_DRM)
|
#if defined(PLATFORM_RPI) || defined(PLATFORM_DRM)
|
||||||
int defaultMode; // Default keyboard mode
|
int defaultMode; // Default keyboard mode
|
||||||
|
|
@ -767,6 +768,7 @@ void InitWindow(int width, int height, const char *title)
|
||||||
// Initialize global input state
|
// Initialize global input state
|
||||||
memset(&CORE.Input, 0, sizeof(CORE.Input));
|
memset(&CORE.Input, 0, sizeof(CORE.Input));
|
||||||
CORE.Input.Keyboard.exitKey = KEY_ESCAPE;
|
CORE.Input.Keyboard.exitKey = KEY_ESCAPE;
|
||||||
|
CORE.Input.Keyboard.useRepeats = false;
|
||||||
CORE.Input.Mouse.scale = (Vector2){ 1.0f, 1.0f };
|
CORE.Input.Mouse.scale = (Vector2){ 1.0f, 1.0f };
|
||||||
CORE.Input.Mouse.cursor = MOUSE_CURSOR_ARROW;
|
CORE.Input.Mouse.cursor = MOUSE_CURSOR_ARROW;
|
||||||
CORE.Input.Gamepad.lastButtonPressed = 0; // GAMEPAD_BUTTON_UNKNOWN
|
CORE.Input.Gamepad.lastButtonPressed = 0; // GAMEPAD_BUTTON_UNKNOWN
|
||||||
|
|
@ -3680,6 +3682,13 @@ void SetExitKey(int key)
|
||||||
#endif
|
#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)
|
// NOTE: Gamepad support not implemented in emscripten GLFW3 (PLATFORM_WEB)
|
||||||
|
|
||||||
// Check if a gamepad is available
|
// Check if a gamepad is available
|
||||||
|
|
@ -5427,7 +5436,8 @@ static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, i
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Check if there is space available in the key queue
|
// 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
|
// Add character to the queue
|
||||||
CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount] = key;
|
CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount] = key;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user