al_get_mouse_state(3)

πŸ“¦
version 5.2.11.3 Β· 3 versions
, in arch rolling

πŸ’– al_get_mouse_state(3) πŸ’–

okay so this one's from the Allegro reference manual (the Library Functions Manual girlies, you know the vibe) and honestly? it's a little baddie of a function. let's get into it 🫢


✨ NAME ✨

al_get_mouse_state β€” literally the Allegro 5 API, that's the whole name, no notes πŸ‘‘


πŸŽ€ SYNOPSIS πŸŽ€

#include <allegro5/allegro.h>

void al_get_mouse_state(ALLEGRO_MOUSE_STATE *ret_state)

bestie it takes one pointer and returns void. that's it. that's the whole function signature. she's lowkey minimalist πŸ’…


🌸 DESCRIPTION 🌸

okay so what she does: she saves the state of the mouse into the structure you hand her β€” and it's the state at the exact moment the function is called, so it's like a little snapshot, a freeze-frame, a polaroid of your mouse's whole life at that instant πŸ“Έ no cap.

πŸ¦‹ the example (yes we're doing this, it's iconic)

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. */
}

so the way this works β€” you do a bitwise AND on state.buttons and the flags are 1, 2, and 4. 1 is the Primary (e.g. left) button, 2 is the Secondary (e.g. right) button, and 4 is the Tertiary (e.g. middle) button. that's the main character energy of bit flags right there πŸ”₯ and notice the position print out lives inside the first if β€” state.x and state.y and a printf("Mouse position: (%d, %d)\n", state.x, state.y) β€” so she only gossips about coordinates when the primary button is held, periodt πŸ’€


πŸ‘€ SEE ALSO πŸ‘€


πŸ’œ reminder bestie: the structure gets the state as of the moment you call the function, so don't be out here assuming it updates by itself. you call, you get the snapshot, you move on. iykyk ✨

and that's the whole page! 🌈 brought to you by the Allegro reference manual β€” al_get_mouse_state(3), signing off, mwah πŸŽ€πŸ§šπŸ’–

πŸ“¦ where this page comes from
  • arch rolling: allegro 5.2.11.3-2 Β· Zlib AND BSD-3-Clause AND OFL-1.1 AND LicenseRef-Custom
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms