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 zero to 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 πŸ¦‹


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 πŸ‘‘βœ¨