al_get_mouse_state(3alleg5)

πŸ“¦
version 5.2.11.3 Β· 4 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ NAME ✨

al_get_mouse_state β€” okay so this is the Allegro 5 API function that grabs a snapshot of where your mouse is at and what it's doing, bestie πŸ’–


πŸŽ€ SYNOPSIS πŸŽ€

#include <allegro5/allegro.h>

void al_get_mouse_state(ALLEGRO_MOUSE_STATE *ret_state)

πŸ¦‹ DESCRIPTION πŸ¦‹

So the way this works is: the second you call it, it saves the state of the mouse β€” like, right at that exact moment β€” and shoves it into the structure you handed over. Snapshot. Frozen in time. Main character energy for real. πŸ“Έ

It's giving "the mouse was doing this, at this instant, and now you know." No cap.

Example, because obviously you want one:

ALLEGRO_MOUSE_STATE state;

al_get_mouse_state(&state);
if (state.buttons & 1) {
    /* Primary (e.g. left) mouse button is held. */
    printf("Mouse position: (%d, %d)\n", state.x, state.y);
}
if (state.buttons & 2) {
    /* Secondary (e.g. right) mouse button is held. */
}
if (state.buttons & 4) {
    /* Tertiary (e.g. middle) mouse button is held. */
}

See how state.buttons & 1 is the primary (e.g. left) mouse button being held? And 2 is the secondary (e.g. right), and 4 is the tertiary (e.g. middle)? That's the whole vibe check right there. πŸ’… Literally just bitmask things, iykyk.


🌸 SEE ALSO 🌸


And that's the page, bestie! 🫢 This was al_get_mouse_state(3alleg5), brought to you by the Allegro reference manual. Go forth and read that mouse state. Slay. πŸ‘‘πŸ’œ

πŸ“¦ where this page comes from