mouse_x(3alleg4)
β¨ mouse_x β bestie, it's the mouse page β¨
okay so real talk, this is from the Allegro game programming library manual, and it's covering a whole lil squad of global variables: mouse_x, mouse_y, mouse_z, mouse_w, mouse_b, and mouse_pos. they all just hang out in global scope holding the mouse's position and button state. no cap. ππ
πΈ SYNOPSIS πΈ
#include <allegro.h>
extern volatile int mouse_x;
extern volatile int mouse_y;
extern volatile int mouse_z;
extern volatile int mouse_w;
extern volatile int mouse_b;
extern volatile int mouse_pos;
π DESCRIPTION π
So these are global variables and they hold the current mouse position plus the button state, okay? and here's the thing β wherever it's possible, these values get updated asynchronously, like they just do it themselves, main character energy, no help needed. β¨
BUT. ifmouse_needs_poll()returnsTRUE, bestie, you have to manually callpoll_mouse()to refresh them with the current input state. it's giving "you gotta do it yourself", no shortcuts. π
Here's the breakdown of who holds what:
mouse_xandmouse_yβ these are integers ranging from zero all the way to the bottom right corner of the screen. iconic.mouse_zandmouse_wβ these hold the current vertical and horizontal wheel position, but only when you're using an input driver that supports wheel mice. if your driver doesn't, well, not them being useful πmouse_bβ this one's a bitfield showing the state of each button:- bit 0 β the left button
- bit 1 β the right button
- bit 2 β the middle button
- higher bits β additional non standard mouse buttons might show up there, so like, extra buttons can absolutely be lurking up in there π«Ά
Usage example, and it's literally this:
if (mouse_b & 1)
printf("Left button is pressed\n");
if (!(mouse_b & 2))
printf("Right button is not pressed\n");
Now mouse_pos, she's the clever one. π She's got the current X coordinate in the upper 16 bits and the Y in the lower 16 bits. why do you care? because this is lowkey perfect for tight polling loops β imagine a mouse interrupt pops off between you reading the two separate variables, that's a whole vibe check failure π. but with mouse_pos you copy the value into a local variable with a single instruction and then split it up at your leisure. obsessed.
Example, verbatim:
int pos, x, y;
pos = mouse_pos;
x = pos >> 16;
y = pos & 0x0000ffff;
π SEE ALSO π
go read these too bestie, they're the whole friend group:
install_mouse(3alleg4)poll_mouse(3alleg4)mouse_needs_poll(3alleg4)exalpha(3alleg4)exlights(3alleg4)exmouse(3alleg4)exshade(3alleg4)exspline(3alleg4)extrans(3alleg4)
and that's the page, periodt. π this was the Allegro manual, version 4.4.3, and yeah the page is literally named mouse_x(3alleg4). go press some buttons, bestie, you've got this π
β¨π¦
π¦ where this page comes from
- debian bookworm: allegro4-doc 2:4.4.3.1-3 Β· Allegro-gift-ware
- debian trixie: allegro4-doc 2:4.4.3.1-5 Β· Allegro-gift-ware
- ubuntu jammy: allegro4-doc 2:4.4.3.1-2 Β· Allegro-gift-ware
- ubuntu noble: allegro4-doc 2:4.4.3.1-4.1build3 Β· Allegro-gift-ware
- ubuntu questing: allegro4-doc 2:4.4.3.1-6
- ubuntu resolute: allegro4-doc 2:4.4.3.1-7 Β· Allegro-gift-ware
- ubuntu stonking: allegro4-doc 2:4.4.3.1-9 Β· Allegro-gift-ware
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms