SDL_GetGlobalMouseState(3)
π SDL_GetGlobalMouseState(3) π
okay bestie, welcome to the SDL3 FUNCTIONS section of the manual, and today's main character is SDL_GetGlobalMouseState πβ¨
πΈ NAME πΈ
SDL_GetGlobalMouseState β go ask the platform, right this second, what the async mouse button state is and where the platform-cursor is sitting relative to the desktop π
π SYNOPSIS π
#include <SDL3/SDL_mouse.h>
SDL_MouseButtonFlags SDL_GetGlobalMouseState(float *x, float *y);
β¨ DESCRIPTION β¨
So likeβ¦ this function immediately queries the platform for the most recent asynchronous state. No waiting, no caching, just straight to the source. And yes queen, that means it's more costly than just grabbing SDL's cached state over in SDL_GetMouseState() π so don't spam it unless you actually need the fresh-from-the-platform tea.
If you pass non-NULL pointers to x or y, it'll write those destinations with the respective x or y coordinates, relative to the desktop π₯οΈ
Now, in Relative Mode? The platform-cursor's position usually contradicts the SDL-cursor's position, the one you'd manually calculate from SDL_GetMouseState() and SDL_GetWindowPosition. They just don't vibe the same way, iykyk π
This function is lowkey perfect when you need to track the mouse outside of a specific window and SDL_CaptureMouse() just isn't fitting your needs. For example, it's giving exactly what you want if you're tracking the mouse while dragging a window, where coordinates relative to a window might not be in sync at all times π iconic behavior honestly.
π¦ FUNCTION PARAMETERS π¦
xβ a pointer to receive the platform-cursor's x-position from the desktop's top left corner. Can beNULLif unused πyβ a pointer to receive the platform-cursor's y-position from the desktop's top left corner. Can beNULLif unused π
π RETURN VALUE π
Returns a 32-bit bitmask of the button state π― and you can bitwise-compare it against the SDL_BUTTON_MASK(X) macro. That's the whole deal, no cap.
π§ THREAD SAFETY π§
This function should only be called on the main thread. periodt. don't try it anywhere else bestie π«
β AVAILABILITY β
This function is available since SDL 3.2.0 π
π₯ SEE ALSO π₯
and that's the whole page, bestie!! this lil gem lives in Simple Directmedia Layer, running SDL 3.4.18 β mwah, go track that mouse ππ¦β¨
π¦ 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