ureadkey(3alleg4)

✨ ureadkey ✨

okay bestie, gather round, because this one is a certified bop πŸ’– it lives in the Allegro game programming library, and it does one thing and does it gorgeously: it hands you the next unicode character from the keyboard buffer. no cap. πŸ‘‘


🌸 SYNOPSIS 🌸

#include <allegro.h>

int ureadkey(int *scancode);

that's it. that's the whole vibe. one include, one function, infinite slay. πŸ¦‹


πŸ’… DESCRIPTION πŸ’…

so here's the tea, fr fr: ureadkey returns the next character from the keyboard buffer, in Unicode format. and if the buffer is literally empty? it just waits. sits there. patiently. like a bestie holding your spot in line until a key gets pressed. 🫢

wanna know if there are already queued keypresses chilling in there before you commit? that's what keypressed() is for, go check it, iykyk. πŸ’œ

the return value carries the Unicode value of the key. and if that pointer argument isn't NULL, it gets set to the scancode β€” so you get both the character and the physical key info. main character energy honestly. πŸ‘‘

and the way that readkey() could never β€” because unlike readkey(), this function is able to return character values greater than 255. that's the whole point. that's the flex. πŸ’…βœ¨

example time, because we love a demo:

int val, scancode;
...
val = ureadkey(&scancode);
if (val == 0x00F1)
   allegro_message("You pressed n with tilde\n");

if (val == 0x00DF)
   allegro_message("You pressed sharp s\n");

look at her go πŸ˜­πŸ’– those are the exact magic numbers, don't touch them.

you should be able to find Unicode character maps over at http://www.unicode.org/ β€” go wild, go browse, it's giving reference material 🌈

⚠️ DOS besties listen up!! remember that on DOS you must specify a custom keyboard map (like those found in keyboard.dat) β€” usually with the help of a configuration file specifying the language mapping (the keyboard variable in the system section of allegro.cfg). if you don't? you get the default US keyboard mapping. that's not a vibe check you want to fail. 😭

πŸŽ€ SEE ALSO πŸŽ€

go read them all, they're all iconic in their own way πŸ§šπŸ’œ


Allegro Β· version 4.4.3 Β· ureadkey(3alleg4)

and that's the whole page bestie, mwah, go press some keys πŸ’‹πŸŒΈπŸŽ€