From 6ff74563ef564114440684929c792eaff3f22cda Mon Sep 17 00:00:00 2001 From: Mao JunJie Date: Tue, 27 Jan 2026 21:06:06 -0500 Subject: [PATCH] fix IsMouseButtonDown\Pressed\Released\Up will get randomly returned to true when the button code is outside the range of mouse button --- src/rcore.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/rcore.c b/src/rcore.c index 8d2a9ca0a..8ede18cc1 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -4047,12 +4047,15 @@ float GetGamepadAxisMovement(int gamepad, int axis) // NOTE: Functions with a platform-specific implementation on rcore_.c //void SetMousePosition(int x, int y) //void SetMouseCursor(int cursor) +#define ArrayCount(arr) (sizeof(arr) / sizeof((arr)[0])) // Check if a mouse button has been pressed once bool IsMouseButtonPressed(int button) { bool pressed = false; - + + if ((button < 0) || (button > MOUSE_BUTTON_BACK)) return false; + if ((CORE.Input.Mouse.currentButtonState[button] == 1) && (CORE.Input.Mouse.previousButtonState[button] == 0)) pressed = true; // Map touches to mouse buttons checking @@ -4065,7 +4068,9 @@ bool IsMouseButtonPressed(int button) bool IsMouseButtonDown(int button) { bool down = false; - + + if ((button < 0) || (button > MOUSE_BUTTON_BACK)) return false; + if (CORE.Input.Mouse.currentButtonState[button] == 1) down = true; // NOTE: Touches are considered like mouse buttons @@ -4078,7 +4083,9 @@ bool IsMouseButtonDown(int button) bool IsMouseButtonReleased(int button) { bool released = false; - + + if ((button < 0) || (button > MOUSE_BUTTON_BACK)) return false; + if ((CORE.Input.Mouse.currentButtonState[button] == 0) && (CORE.Input.Mouse.previousButtonState[button] == 1)) released = true; // Map touches to mouse buttons checking @@ -4091,7 +4098,9 @@ bool IsMouseButtonReleased(int button) bool IsMouseButtonUp(int button) { bool up = false; - + + if ((button < 0) || (button > MOUSE_BUTTON_BACK)) return false; + if (CORE.Input.Mouse.currentButtonState[button] == 0) up = true; // NOTE: Touches are considered like mouse buttons