keyboard_ucallback(3)

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

🌸 NAME 🌸

keyboard_ucallback β€” your very own user specified unicode keyboard callback handler πŸ’– and it lives in the Allegro game programming library, bestie.


✨ SYNOPSIS ✨

#include <allegro.h>

extern int (*keyboard_ucallback)(int key, int *scancode);

πŸŽ€ DESCRIPTION πŸŽ€

Okay so. This is the unicode-aware version of keyboard_callback(). The way that it works is: if you set it, the keyboard handler calls it in response to every single keypress. Every one. No skips. πŸ’…

What gets passed in is the character value and the scancode that are about to be added into the input buffer. Your function is allowed to modify the scancode value, and it returns a new or modified key code. That's the whole deal β€” you get a say before it lands in the buffer. πŸ‘‘

And here's the lil trapdoor: if it both sets the scancode to zero and returns zero, the keypress gets ignored entirely. Poof. Gone. Not in the buffer, not your problem. πŸ«₯

⚠️ Real talk though β€” this routine executes in an interrupt context, so it has to be in locked memory. Not optional. Do not skip this. 😭

Example, because a vibe check is always better with code:

int silence_g_key(int key, int *scancode)
{
   if (key == 'g') {
      *scancode = 0;
      return 0;
   }
   return key;
} END_OF_FUNCTION(silence_g_key)

...

   install_timer();
   LOCK_FUNCTION(silence_g_key);
   install_keyboard();
   keyboard_ucallback = silence_g_key;

Note that this keyboard callback has priority over the non unicode callback. So if you set both of them? Only the unicode one will work. The other one is just standing there like 🧍. Sorry babe.


πŸ¦‹ SEE ALSO πŸ¦‹


Okay that's the whole page, bestie, you ate it πŸ’– this was Allegro, version 4.4.3, and it's keyboard_ucallback(3) β€” go lock that memory and slay βœ¨πŸŽ€

πŸ“¦ where this page comes from