keyboard_callback(3alleg4)
β¨ NAME β¨
keyboard_callback β bestie, this is your user specified keyboard callback handler, straight out of the Allegro game programming library π
πΈ SYNOPSIS πΈ
#include <allegro.h>
extern int (*keyboard_callback)(int key);
π DESCRIPTION π
okay so. If you set this function, the keyboard handler literally calls it in response to every single keypress π It gets handed a copy of the value that's about to be added into the input buffer, and then you, the main character, get to decide what happens next:
- return that value unchanged and everything stays as-is,
- return
zeroto make the key get ignored entirely (ghosted, gone, bye π), - or return a modified value to change what
readkey()will later give back.
β οΈ Important caveat, no cap: this routine executes in an interrupt context, so it must be in locked memory. Like, non-negotiable.
Here's the example from the page, verbatim π«Ά:
int enigma_scrambler(int key)
{
/* Add one to both the scancode and ascii values. */
return (((key >> 8) + 1)
}
END_OF_FUNCTION(enigma_scrambler)
...
install_timer();
LOCK_FUNCTION(enigma_scrambler);
install_keyboard();
keyboard_callback = enigma_scrambler;
Also!! Heads up: this callback will be ignored if you also set the unicode keyboard callback. So don't do both and then be confused, iykyk π
π¦ SEE ALSO π¦
install_keyboard(3alleg4)readkey(3alleg4)ureadkey(3alleg4)keyboard_ucallback(3alleg4)keyboard_lowlevel_callback(3alleg4)
mwah π this page came to you from Allegro, version 4.4.3, and it's giving keyboard_callback(3alleg4) energy β go lock your memory and slay, bestie πβ¨
π¦ 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