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 be NULL if unused πŸ’œ
  • y β€” a pointer to receive the platform-cursor's y-position from the desktop's top left corner. Can be NULL if 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