key_shifts(3alleg4)

πŸ’… key_shifts β€” the Allegro manual, bestie edition ✨

okay so. this is key_shifts(3alleg4) from the Allegro manual, aka the Allegro game programming library. buckle up πŸŽ€


✨ NAME ✨

key_shifts β€” a bitmask containing the current state of the modifier keys. it lives in the Allegro game programming library, and it is literally the vibe check for your keyboard's mood πŸ‘‘


🌸 SYNOPSIS 🌸

#include <allegro.h>

extern volatile int key_shifts;

that's it. that's the whole thing. a single volatile int. iconic behaviour, no notes πŸ’–


πŸ¦‹ DESCRIPTION πŸ¦‹

so key_shifts is a bitmask holding the current state of shift / ctrl / alt, the special Windows keys, and the accent escape characters. she's holding a LOT of info in one little int and honestly? slay. πŸ’…

wherever possible this value gets updated asynchronously β€” like, she's doing her own thing, no input from you required. BUT 🚨 if keyboard_needs_poll() returns TRUE, then bestie you have to manually call poll_keyboard() to refresh it with the current input state. no cap, that's on you. don't forget it.

this value can contain any of these flags:

  • KB_SHIFT_FLAG
  • KB_CTRL_FLAG
  • KB_ALT_FLAG
  • KB_LWIN_FLAG
  • KB_RWIN_FLAG
  • KB_MENU_FLAG
  • KB_COMMAND_FLAG
  • KB_SCROLOCK_FLAG
  • KB_NUMLOCK_FLAG
  • KB_CAPSLOCK_FLAG
  • KB_INALTSEQ_FLAG
  • KB_ACCENT1_FLAG
  • KB_ACCENT2_FLAG
  • KB_ACCENT3_FLAG
  • KB_ACCENT4_FLAG

πŸ“ example (yes it's giving main character energy) πŸ“

if (key[KEY_W]) {
   if (key_shifts & KB_SHIFT_FLAG) {
      /* User is pressing shift + W. */
   } else {
      /* Hmmm... lower case W then. */
   }
}

see how she reads? bitwise & and suddenly you know whether the user is screaming W or just gently typing w. the range?? unmatched 😭✨


πŸ‘‘ SEE ALSO πŸ‘‘

go read those too, they're the rest of the friend group 🫢


and that's the whole page, bestie 🌈 brought to you by Allegro, version 4.4.3, on the key_shifts(3alleg4) page. mwah, take care of your modifier keys πŸ’–πŸŽ€πŸ¦‹