[rcore] IsMouseButton*(), random key codes return unexpected results (#5516)

* update

* update

* stuff

* update

* move headerfile to root

* delete .h

* update ignore

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

* remove unessary macro

* refactor IsMouseButton*() early returns
This commit is contained in:
Jason Mao
2026-01-28 13:26:07 -05:00
committed by GitHub
parent 63e4fd838d
commit d0a6892989

View File

@ -4053,10 +4053,15 @@ bool IsMouseButtonPressed(int button)
{ {
bool pressed = false; bool pressed = false;
if ((CORE.Input.Mouse.currentButtonState[button] == 1) && (CORE.Input.Mouse.previousButtonState[button] == 0)) pressed = true; if ((button >= 0) && (button <= MOUSE_BUTTON_BACK))
{
// Map touches to mouse buttons checking if ((CORE.Input.Mouse.currentButtonState[button] == 1) && (CORE.Input.Mouse.previousButtonState[button] == 0)) pressed = true;
if ((CORE.Input.Touch.currentTouchState[button] == 1) && (CORE.Input.Touch.previousTouchState[button] == 0)) pressed = true;
// Map touches to mouse buttons checking
if ((CORE.Input.Touch.currentTouchState[button] == 1) && (CORE.Input.Touch.previousTouchState[button] == 0)) pressed = true;
}
return pressed; return pressed;
} }
@ -4066,10 +4071,15 @@ bool IsMouseButtonDown(int button)
{ {
bool down = false; bool down = false;
if (CORE.Input.Mouse.currentButtonState[button] == 1) down = true; if ((button >= 0) && (button <= MOUSE_BUTTON_BACK))
{
// NOTE: Touches are considered like mouse buttons if (CORE.Input.Mouse.currentButtonState[button] == 1) down = true;
if (CORE.Input.Touch.currentTouchState[button] == 1) down = true;
// NOTE: Touches are considered like mouse buttons
if (CORE.Input.Touch.currentTouchState[button] == 1) down = true;
}
return down; return down;
} }
@ -4079,10 +4089,15 @@ bool IsMouseButtonReleased(int button)
{ {
bool released = false; bool released = false;
if ((CORE.Input.Mouse.currentButtonState[button] == 0) && (CORE.Input.Mouse.previousButtonState[button] == 1)) released = true; if ((button >= 0) && (button <= MOUSE_BUTTON_BACK))
{
// Map touches to mouse buttons checking if ((CORE.Input.Mouse.currentButtonState[button] == 0) && (CORE.Input.Mouse.previousButtonState[button] == 1)) released = true;
if ((CORE.Input.Touch.currentTouchState[button] == 0) && (CORE.Input.Touch.previousTouchState[button] == 1)) released = true;
// Map touches to mouse buttons checking
if ((CORE.Input.Touch.currentTouchState[button] == 0) && (CORE.Input.Touch.previousTouchState[button] == 1)) released = true;
}
return released; return released;
} }
@ -4092,10 +4107,15 @@ bool IsMouseButtonUp(int button)
{ {
bool up = false; bool up = false;
if (CORE.Input.Mouse.currentButtonState[button] == 0) up = true; if ((button >= 0) && (button <= MOUSE_BUTTON_BACK))
{
// NOTE: Touches are considered like mouse buttons if (CORE.Input.Mouse.currentButtonState[button] == 0) up = true;
if (CORE.Input.Touch.currentTouchState[button] == 0) up = true;
// NOTE: Touches are considered like mouse buttons
if (CORE.Input.Touch.currentTouchState[button] == 0) up = true;
}
return up; return up;
} }