Search code examples
c++sdl-2

How to detect if left mousebutton is being held down with SDL2


I know how to use events to detect when the mouse button is pressed, however, how do detect if a mouse button is currently held down? Note I am not asking how to get it from an event.

I have not tried anything apart from SDL_GetMouseState(&x, &y); however it seems to only return the X and Y position of the mouse.


Solution

  • SDL_GetMouseState() returns the buttons that were pressed. Example:

    if (SDL_GetMouseState(...) & SDL_BUTTON_LMASK)
        // Left button is pressed.