KEYBOARD_LOWLEVEL_CALLBACK(3alleg4)
π NAME π
keyboard_lowlevel_callback β bestie, this is your user specified low level keyboard event handler. It's part of the Allegro game programming library, and it is genuinely the rawest, most backstage-pass way to hear about keyboard stuff. π
β¨ SYNOPSIS β¨
#include <allegro.h>
extern void (*keyboard_lowlevel_callback)(int scancode);
π DESCRIPTION π
Okay so picture this: if you set this function, the keyboard handler calls it in response to every single keyboard event. Not just presses β presses including keyboard repeat rate, and releases too. Every event. It's giving main character energy in the interrupt handler. π
What gets passed in is a raw keyboard scancode byte. And bestie, scancodes are 7 bits long, so listen carefully:
- the top bit (that's the 8th bit) is clear if the key has been pressed β¨
- the top bit is set if the key has been released π
π¨ Real talk: this routine executes in an interrupt context, so it must be in locked memory. No cap. Lock it or it's over.
Example, and yes this is the whole vibe:
volatile int key_down, key_up;
void keypress_watcher(int scancode)
{
if (scancode & 0x80) {
key_up = 1;
} else {
key_down = 1;
}
} END_OF_FUNCTION(keypress_watcher)
...
install_timer();
LOCK_FUNCTION(silence_g_key);
LOCK_VARIABLE(key_down);
LOCK_VARIABLE(key_up);
install_keyboard();
keyboard_lowlevel_callback = keypress_watcher;
/* Disable keyboard repeat to get typewriter effect. */
set_keyboard_rate(0, 0);
...
while (game_loop) {
if (key_down) {
key_down = 0;
/* Play sample of typewriter key press. */
}
if (key_up) {
key_up = 0;
/* Play sample of typewriter key release. */
}
}
π SEE ALSO π
And that's the whole page, bestie!! π«Ά This was the Allegro manual, version 4.4.3, and honestly she ate. Go lock your memory and slay your keyboard events, ily, bye!! πβ¨π
π¦ 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