poll_keyboard(3alleg4)

πŸ’… poll_keyboard πŸ’…

okay so bestie, welcome to poll_keyboard β€” the lil function from the Allegro game programming library that literally just goes "hey. keyboard. u up? πŸ‘€" and updates the keyboard state for you. that's it. that's the whole job. and honestly? iconic for it. 🌸


✨ SYNOPSIS ✨

#include <allegro.h>

int poll_keyboard();

like. one line. no arguments. she's low maintenance. we love a low maintenance queen. πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea. whenever it's possible, Allegro reads your keyboard input asynchronously β€” meaning it's happening from inside an interrupt handler, doing its own thing in the background, no help needed from you, main character energy fr fr. πŸ’–

BUT. and this is the important part, bestie β€” on some platforms that just isn't possible. and on those platforms, you must call this routine at regular intervals to update the keyboard state variables. no calling = no updates. the vibe check fails. 😭

now here's the part that lowkey trips everyone up: to help you test your keyboard polling code, even if you're programming on a platform that doesn't require it, after the first time you call this function, Allegro will switch into polling mode. so from that point onwards you will have to call this routine in order to get any keyboard input at all β€” regardless of whether the current driver actually needs to be polled or not. so once you go poll, you don't go back. periodt. πŸ’€

and here's the shortcut you need to know about: the keypressed(), readkey(), and ureadkey() functions call poll_keyboard() automatically. so you only need to use this function when you're accessing the key[] array and the key_shifts variable. iykyk. 🫢


⭐ RETURN VALUE ⭐

returns zero on success ✨, or a negative number on failure (ie. no keyboard driver installed πŸ™ˆ).

ngl a negative return here is giving "who even are you" energy. check your install, bestie.

πŸŽ€ SEE ALSO πŸŽ€

go read those too, they're all part of the same little keyboard friend group. 🧚


and that's the whole page, bestie!! brought to you by Allegro, version 4.4.3 πŸ’œ β€” she's giving vintage but she's still slaying. now go poll that keyboard and make it do something cute. bye babes!! πŸŒˆπŸ’–βœ¨