scancode_to_ascii(3alleg4)

πŸ’– scancode_to_ascii πŸ’–

okay bestie, so this one lives in the Allegro manual (that's the 3alleg4 section, iykyk) and it's literally just vibes: you hand it a key, it hands you back a letter. πŸŽ€


✨ NAME ✨

scancode_to_ascii β€” converts a scancode to an ASCII character. part of the Allegro game programming library, no cap. πŸ¦‹


🌸 SYNOPSIS 🌸

#include <allegro.h>

int scancode_to_ascii(int scancode);

πŸ’… DESCRIPTION πŸ’…

so here's the tea β˜• β€” this function takes the scancode you give it and converts it into the ASCII character for that key. it's giving "what does this key actually type". and yes, it mangles Unicode values, that's just part of the deal, don't @ me.

what you get back is the unshifted, uncapslocked result of pressing that key. so no, it's not gonna read your mind about whether you were holding shift or had caps lock on β€” it's the raw, lowercase, baseline truth. periodt. πŸ’œ

and if the key isn't a character-generating key, or the lookup just can't be done at all? you get zero. that's it. that's the answer. 🫢

the lookup straight up cannot happen for keys like the F1–F12 keys or the cursor keys β€” those are just not that girl when it comes to ASCII, bestie. πŸ’€

also, heads up: some drivers will only return approximate values. so like, don't bet your whole main character arc on it being pixel-perfect for every single driver out there. πŸ™ˆ

and if your actual goal is showing the name of a key to a human, you should lowkey be using the scancode_to_name function instead. that's the one built for that. scancode_to_ascii is not the moment. ✨

πŸ“ Example πŸ“

okay so this is literally the whole vibe in code:

int ascii;
...
ascii = scancode_to_ascii(scancode);
allegro_message("You pressed '%c'\n", ascii);

you grab the ascii value, you print it, everyone claps. slay. πŸ‘‘


🌈 SEE ALSO 🌈

  • scancode_to_name(3alleg4) β€” the other one, for when you want the key's name instead of its character. obsessed with her honestly. πŸ’–

and that's a wrap on the Allegro manual, version 4.4.3 πŸŽ€ β€” go forth, convert your scancodes, be the main character of your own keyhandler. mwah. πŸ’…βœ¨