---
name: "SDL_GetMouseState"
section: "3"
platform: "linux"
package: "libsdl3-doc"
version: "3.2.10+ds-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/SDL_GetMouseState"
---

# SDL\_GetMouseState(3)

Query SDL's cache for the synchronous mouse button state and the window-relative SDL-cursor position.

## NAME

SDL\_GetMouseState - Query SDL's cache for the synchronous mouse button state and the window-relative SDL-cursor position.

## HEADER FILE

Defined in SDL3/SDL\_mouse.h

## SYNOPSIS

```
#include "SDL3/SDL.h"
```

**SDL\_MouseButtonFlags SDL\_GetMouseState(float \*x, float \*y);**

## DESCRIPTION

This function returns the cached synchronous state as SDL understands it from the last pump of the event queue.

To query the platform for immediate asynchronous state, use

**SDL\_GetGlobalMouseState** .

Passing non-NULL pointers to **x** or **y** will write the destination with respective x or y coordinates relative to the focused window.

In Relative Mode, the SDL-cursor's position usually contradicts the platform-cursor's position as manually calculated from

**SDL\_GetGlobalMouseState** () and

**SDL\_GetWindowPosition** .

## FUNCTION PARAMETERS

- *x*

  a pointer to receive the SDL-cursor's x-position from the focused window's top left corner, can be NULL if unused.

- *y*

  a pointer to receive the SDL-cursor's y-position from the focused window's top left corner, can be NULL if unused.

## RETURN VALUE

( **SDL\_MouseButtonFlags** ) Returns a 32-bit bitmask of the button state that can be bitwise-compared against the

**SDL\_BUTTON\_MASK** (X) macro.

## THREAD SAFETY

This function should only be called on the main thread.

## AVAILABILITY

This function is available since SDL 3.2.0.

## SEE ALSO

**•**(3), [**SDL\_GetGlobalMouseState**(3)](/SDL_GetGlobalMouseState/3.md), **•**(3), [**SDL\_GetRelativeMouseState**(3)](/SDL_GetRelativeMouseState/3.md)
