SDL_GetMouseState(3)
π SDL_GetMouseState π
okay bestie, welcome to the SDL3 FUNCTIONS corner of the man pages, where we're talking about SDL_GetMouseState(3) β yes, the mouse one, the one you've been googling at 2am. let's get into it πβ¨
β¨ NAME β¨
SDL_GetMouseState β it queries SDL's own little cache for the synchronous mouse button state plus the window-relative SDL-cursor position. no cap, that's literally the whole job π
π SYNOPSIS π
#include <SDL3/SDL_mouse.h>
SDL_MouseButtonFlags SDL_GetMouseState(float *x, float *y);
that's it. two little float * besties and a return type that is not a vibe, it's a bitmask. iykyk πΈ
π¦ DESCRIPTION π¦
so here's the tea: this function hands you back the cached synchronous state β as in, SDL's best understanding of things, from the last pump of the event queue. it's not asking the platform anything right now, it's reading SDL's notes π
if you want to interrogate the platform for the immediate asynchronous state, that's a different function, bestie β go say hi to SDL_GetGlobalMouseState.
if you pass non-NULL pointers into x or y, it'll write the destination with the respective x or y coordinates relative to the focused window. focused window. keep that in your head, it matters π
and now the messy part, the drama: in Relative Mode, the SDL-cursor's position usually contradicts the platform-cursor's position β the one you'd manually calculate from SDL_GetGlobalMouseState() and SDL_GetWindowPosition. it's giving two sources of truth fighting in the group chat π don't be surprised when they don't match.
π FUNCTION PARAMETERS π
xβ a pointer to receive the SDL-cursor's x-position, measured from the focused window's top left corner. can beNULLif you're not using it, no hard feelings π«Άyβ a pointer to receive the SDL-cursor's y-position, measured from the focused window's top left corner. also can beNULLif unused. slay, optional parameters, we love to see it π
β RETURN VALUE β
it returns a 32-bit bitmask of the button state. and here's the move: you bitwise-compare it against the SDL_BUTTON_MASK(X) macro. that's the whole bitwise ritual, periodt π₯
π THREAD SAFETY π
main thread only. this function should only be called on the main thread. do not take it to a worker thread, it will not survive the vibe check π
π§ AVAILABILITY π§
this function has been available since SDL 3.2.0. if you're on anything older, you're on your own, bestie π
π SEE ALSO π
go read those too, they're all in the same friend group πΈ
and that's the page!! brought to you by Simple Directmedia Layer, running SDL 3.4.18 β go forth and query your mouse state, you absolute icon πβ¨ππ¦
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms