SDL_KeyboardEvent(3type)

πŸ’… SDL_KeyboardEvent β€” the keyboard event struct, bestie

okay so you're here for SDL_KeyboardEvent(3type), the keyboard button event structure (event.key.*) from the SDL3 datatypes club. pull up a chair, this one's actually adorable once you see it. ✨


✨ SYNOPSIS ✨

#include <SDL3/SDL_events.h>

typedef struct SDL_KeyboardEvent
{
    SDL_EventType type;     /**< SDL_EVENT_KEY_DOWN or SDL_EVENT_KEY_UP */
    Uint32 reserved;
    Uint64 timestamp;       /**< In nanoseconds, populated using SDL_GetTicksNS() */
    SDL_WindowID windowID;  /**< The window with keyboard focus, if any */
    SDL_KeyboardID which;   /**< The keyboard instance id, or 0 if unknown or virtual */
    SDL_Scancode scancode;  /**< SDL physical key code */
    SDL_Keycode key;        /**< SDL virtual key code */
    SDL_Keymod mod;         /**< current key modifiers */
    Uint16 raw;             /**< The platform dependent scancode for this event */
    bool down;              /**< true if the key is pressed */
    bool repeat;            /**< true if this is a key repeat */
} SDL_KeyboardEvent;

πŸŽ€ DESCRIPTION πŸŽ€

okay so lowkey the whole plot twist here is key. like, the key is the base SDL_Keycode you get by pressing the scancode using the current keyboard layout, and it also applies any options you specified in SDL_HINT_KEYCODE_OPTIONS. the way it just… does all that for you. πŸ’–

and if you wanna be extra (valid), you can get the SDL_Keycode that corresponds to the event's scancode and mod directly from the keyboard layout, bypassing SDL_HINT_KEYCODE_OPTIONS entirely, by calling SDL_GetKeyFromScancode(). yep. shortcut queen behavior. πŸ‘‘


🌈 AVAILABILITY 🌈

this struct has been serving since SDL 3.2.0. vintage, but like, the good kind. πŸ¦‹


πŸ’œ SEE ALSO πŸ’œ


not me writing a whole love letter to a C struct. anyway. go press some keys, bestie, the events are eventing. πŸ”₯

mwah, this page is brought to you by Simple Directmedia Layer πŸ’… and it's riding with SDL 3.4.18. go forth and keyboard-event responsibly, ily, byeeee πŸŽ€βœ¨πŸ«Ά

πŸ“¦ where this page comes from