Retrieve the current state of the mouse.
Defined in <SDL3/SDL_mouse.h>
x | the x coordinate of the mouse cursor position relative to the focus window |
y | the y coordinate of the mouse cursor position relative to the focus window |
Returns a 32-bit button bitmask of the current button state.
The current button state is returned as a button bitmask, which can be tested using the SDL_BUTTON(X) macro (where X
is generally 1 for the left, 2 for middle, 3 for the right button), and x
and y
are set to the mouse cursor position relative to the focus window. You can pass NULL for either x
or y
.
This function is available since SDL 3.0.0.
float x, y;
Uint32 buttons;
SDL_PumpEvents(); // make sure we have the latest mouse state.
buttons = SDL_GetMouseState(&x, &y);
SDL_Log("Mouse cursor is at %f, %f", x, y);
if ((buttons & SDL_BUTTON_LMASK) != 0) {
SDL_Log("Mouse Button 1 (left) is pressed.");
}