fix IsMouseButtonDown\Pressed\Released\Up will get randomly returned to true when the button code is outside the range of mouse button

This commit is contained in:
Mao JunJie 2026-01-27 21:06:06 -05:00
parent 0f15214e67
commit 6ff74563ef

View File

@ -4047,12 +4047,15 @@ float GetGamepadAxisMovement(int gamepad, int axis)
// NOTE: Functions with a platform-specific implementation on rcore_<platform>.c // NOTE: Functions with a platform-specific implementation on rcore_<platform>.c
//void SetMousePosition(int x, int y) //void SetMousePosition(int x, int y)
//void SetMouseCursor(int cursor) //void SetMouseCursor(int cursor)
#define ArrayCount(arr) (sizeof(arr) / sizeof((arr)[0]))
// Check if a mouse button has been pressed once // Check if a mouse button has been pressed once
bool IsMouseButtonPressed(int button) bool IsMouseButtonPressed(int button)
{ {
bool pressed = false; 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; if ((CORE.Input.Mouse.currentButtonState[button] == 1) && (CORE.Input.Mouse.previousButtonState[button] == 0)) pressed = true;
// Map touches to mouse buttons checking // Map touches to mouse buttons checking
@ -4066,6 +4069,8 @@ bool IsMouseButtonDown(int button)
{ {
bool down = false; bool down = false;
if ((button < 0) || (button > MOUSE_BUTTON_BACK)) return false;
if (CORE.Input.Mouse.currentButtonState[button] == 1) down = true; if (CORE.Input.Mouse.currentButtonState[button] == 1) down = true;
// NOTE: Touches are considered like mouse buttons // NOTE: Touches are considered like mouse buttons
@ -4079,6 +4084,8 @@ bool IsMouseButtonReleased(int button)
{ {
bool released = false; 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; if ((CORE.Input.Mouse.currentButtonState[button] == 0) && (CORE.Input.Mouse.previousButtonState[button] == 1)) released = true;
// Map touches to mouse buttons checking // Map touches to mouse buttons checking
@ -4092,6 +4099,8 @@ bool IsMouseButtonUp(int button)
{ {
bool up = false; bool up = false;
if ((button < 0) || (button > MOUSE_BUTTON_BACK)) return false;
if (CORE.Input.Mouse.currentButtonState[button] == 0) up = true; if (CORE.Input.Mouse.currentButtonState[button] == 0) up = true;
// NOTE: Touches are considered like mouse buttons // NOTE: Touches are considered like mouse buttons