keyboard_callback(3)

πŸ“¦ version 4.4.3.1, in fedora 43, fedora 44

✨ keyboard_callback(3) ✨

okay bestie, welcome to the Allegro manual πŸ’– this one's from the Allegro game programming library, and it's literally about the lil hook you can plug into the keyboard so you get a say in what keys even mean. πŸŽ€


🌸 NAME 🌸

keyboard_callback β€” the user-specified keyboard callback handler. it's giving Allegro game programming library. πŸ‘‘


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <allegro.h>

extern int (*keyboard_callback)(int key);

πŸ’… DESCRIPTION πŸ’…

so here's the tea β˜• if you set this function, the keyboard handler calls it in response to every single keypress. no cap, every one. πŸ’€

it gets handed a copy of the value that's about to get yeeted into the input buffer, and then you get to decide what happens next:

  • return that value unchanged β†’ business as usual, bestie
  • return zero β†’ the key gets ignored entirely, poof, gone πŸ™ˆ
  • return a modified value β†’ you literally change what readkey() will later return. main character energy fr fr ✨
🚨 okay important, do not skip this: this routine executes in an interrupt context, so it must be in locked memory. that's not a vibe suggestion, that's a requirement. 😭

example time, here's the whole situation:

   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;

and one more lil note before you go 🫢 β€” this callback will be ignored if you also set the unicode keyboard callback. pick a lane, babe. πŸ’…


πŸ‘‘ SEE ALSO πŸ‘‘


and that's a wrap, bestie πŸŽ€ this was Allegro, version 4.4.3, and it lives on the keyboard_callback(3) page. slay, go lock your memory, and stay iconic πŸŒˆπŸ’œ

πŸ“¦ where this page comes from