key(3)
π key(3) π β the Allegro manual, but make it bestie
okay so we're in the Allegro manual, and today's main character is key β like, THE key, the one you'll be using every single frame of your game loop. it's a game programming library thing, iykyk. let's get into it π«Ά
β¨ NAME β¨
key β an array of flags that tells you what state each key is in. part of the Allegro game programming library, obviously. π
πΈ SYNOPSIS πΈ
#include <allegro.h>
extern volatile char key[KEY_MAX];
that's it. that's the whole vibe. one array, endless possibilities. β¨
π¦ DESCRIPTION π¦
so key is an array of flags, right? and it's ordered by scancode, one slot per key, telling you the state of each one. whenever it's possible, those values get updated asynchronously β like, they just happen, no effort from you, slay. BUT π¨ if keyboard_needs_poll() returns TRUE, then bestie you're on your own: you have to manually call poll_keyboard() to refresh them with the current input state. no shortcuts, no cap.
the scancodes live in allegro/keyboard.h as a whole series of KEY_* constants (and yeah, they're also listed down below, i got you). for example, you could write something like:
if (key[KEY_SPACE])
printf("Space is pressed\n");
and boom, you're checking if space is held. iconic behaviour honestly.
ngl, one thing to keep in mind: this array is supposed to represent which keys are physically held down and which ones aren't. so semantically, it's read-only. don't go writing into it like it's yours, because it's not. it's the keyboard's. π
these are the keyboard scancodes, the full lineup, no skips:
KEY_A ... KEY_Z,
KEY_0 ... KEY_9,
KEY_0_PAD ... KEY_9_PAD,
KEY_F1 ... KEY_F12,
KEY_ESC, KEY_TILDE, KEY_MINUS, KEY_EQUALS,
KEY_BACKSPACE, KEY_TAB, KEY_OPENBRACE, KEY_CLOSEBRACE,
KEY_ENTER, KEY_COLON, KEY_QUOTE, KEY_BACKSLASH,
KEY_BACKSLASH2, KEY_COMMA, KEY_STOP, KEY_SLASH,
KEY_SPACE,
KEY_INSERT, KEY_DEL, KEY_HOME, KEY_END, KEY_PGUP,
KEY_PGDN, KEY_LEFT, KEY_RIGHT, KEY_UP, KEY_DOWN,
KEY_SLASH_PAD, KEY_ASTERISK, KEY_MINUS_PAD,
KEY_PLUS_PAD, KEY_DEL_PAD, KEY_ENTER_PAD,
KEY_PRTSCR, KEY_PAUSE,
KEY_ABNT_C1, KEY_YEN, KEY_KANA, KEY_CONVERT, KEY_NOCONVERT,
KEY_AT, KEY_CIRCUMFLEX, KEY_COLON2, KEY_KANJI,
KEY_LSHIFT, KEY_RSHIFT,
KEY_LCONTROL, KEY_RCONTROL,
KEY_ALT, KEY_ALTGR,
KEY_LWIN, KEY_RWIN, KEY_MENU,
KEY_SCRLOCK, KEY_NUMLOCK, KEY_CAPSLOCK
KEY_EQUALS_PAD, KEY_BACKQUOTE, KEY_SEMICOLON, KEY_COMMAND
and finally π β you might clock some odd behaviour from KEY_PAUSE. that key only fires off an interrupt when it's pressed, not when it's released. so, because of that, Allegro just pretends the pause key is a state key, which is literally the only way to make it usable. it's giving "we did what we had to do." π
π SEE ALSO π
and that's the whole page, bestie π₯° this was Allegro version 4.4.3, and you just read key(3). go forth and check your keys. periodt. ππ
π¦ 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