mouse_x(3)
β¨ mouse_x β bestie edition β¨
okay so this is the mouse_x(3) page from the Allegro manual, and it's literally just the global variables that hold your mouse's position and button vibes. iconic. let's get into it ππ
πΈ NAME πΈ
mouse_x, mouse_y, mouse_z, mouse_w, mouse_b, mouse_pos β global variables with the mouse position / button state. it's giving Allegro game programming library energy, fr fr.
π¦ 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;
like. six little extern volatile int besties. that's the whole vibe check. π
π DESCRIPTION π
so these are the global variables holding the current mouse position and button state. obsessed.
wherever possible, these values get updated asynchronously β like, they update themselves, main character energy, they don't need you. but (and this is the important part, no cap) if mouse_needs_poll() returns TRUE, you have to manually call poll_mouse() to update them with the current input state. so basically you gotta do the work yourself in that case. π
here's the breakdown, bestie:
mouse_xandmouse_yβ the positions, as integers ranging from zero to the bottom right corner of the screen.mouse_zandmouse_wβ hold the current vertical and horizontal wheel position, when you're using an input driver that supports wheel mice.mouse_bβ a bitfield indicating the state of each button:- bit 0 = the left button
- bit 1 = the right button
- bit 2 = the middle button
- additional non standard mouse buttons might be available as higher bits in this variable π
usage example, because we love a demo:
if (mouse_b & 1)
printf("Left button is pressed\n");
if (!(mouse_b & 2))
printf("Right button is not pressed\n");
see how bit 1 in mouse_b & 1 = left pressed, and !(mouse_b & 2) = right not pressed. yes queen, bitwise. π₯
π the mouse_pos situation π
the mouse_pos variable has the current X coordinate in the upper 16 bits and the Y in the lower 16 bits. it's giving two-for-one, two slays in one int.
this may be useful in tight polling loops, where a mouse interrupt could occur between your reading of the two separate variables β because you can copy this value into a local variable with a single instruction and then split it up at your leisure. atomic-ish behavior, we stan. β¨
example, and yes you're gonna wanna screenshot this:
int pos, x, y;
pos = mouse_pos;
x = pos >> 16;
y = pos & 0x0000ffff;
x from the top bits, y from the bottom bits, 0x0000ffff doing the masking. periodt. π
lowkey important: if you readmouse_xandmouse_yseparately in a tight loop, an interrupt could sneak in between them.mouse_posis the way around that. iykyk.
π SEE ALSO π
install_mouse(3)poll_mouse(3)mouse_needs_poll(3)exalpha(3)exlights(3)exmouse(3)exshade(3)exspline(3)extrans(3)
go read those too bestie, they're all connected, it's a whole cinematic universe π
Allegro, version 4.4.3, and this page is mouse_x(3) β mwah, that's a wrap, hope your mouse always knows where it is π«ΆππΈ
π¦ where this page comes from
- fedora 43: allegro-devel 4.4.3.1-18.fc43 Β· Giftware
- fedora 43: allegro-devel 4.4.3.1-18.fc43 Β· Giftware
- fedora 44: allegro-devel 4.4.3.1-20.fc44 Β· Giftware
- fedora 44: allegro-devel 4.4.3.1-20.fc44 Β· Giftware
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms