SDL_SetWindowKeyboardGrab(3)
β¨ SDL_SetWindowKeyboardGrab(3) β¨
okay bestie, welcome to the SDL3 FUNCTIONS corner of the man pages π this one is SDL_SetWindowKeyboardGrab and it's giving keyboard grab mode, no cap.
π NAME π
SDL_SetWindowKeyboardGrab β set a window's keyboard grab mode. literally that's the whole job. slay.
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_video.h>
bool SDL_SetWindowKeyboardGrab(SDL_Window *window, bool grabbed);
π¦ DESCRIPTION π¦
so, keyboard grab? it enables capture of system keyboard shortcuts like Alt+Tab or the Meta/Super key. yes, the ones your OS is usually gatekeeping. π
but lowkey, not all system keyboard shortcuts can be captured by applications β one example is Ctrl+Alt+Del on Windows. some of those are just untouchable, periodt. π
this is primarily intended for specialized applications such as VNC clients or VM frontends. normal games should not use keyboard grab β like, fr fr, don't do it, that's not your vibe. π
when keyboard grab is enabled, SDL will continue to handle Alt+Tab when the window is full-screen, to ensure the user is not trapped in your application. very considerate of SDL, honestly. if you have a custom keyboard shortcut to exit fullscreen mode, you may suppress this behavior with SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED.
and here's the plot twist π: if the caller enables a grab while another window is currently grabbed, the other window loses its grab in favor of the caller's window. main character energy, but make it window management. it's giving "there can only be one." π
π FUNCTION PARAMETERS π
windowβ the window for which the keyboard grab mode should be set. the one getting the glow-up.grabbedβ this istrueto grab keyboard, andfalseto release. binary queen. β¨
β RETURN VALUE β
Returns true on success or false on failure; call SDL_GetError() for more information. so if it flops, SDL_GetError() will tell you why β always check, bestie, don't just sit there wondering. π
π§ THREAD SAFETY π§
This function should only be called on the main thread. no side-quests on other threads, okay? π«Ά
π AVAILABILITY π
This function is available since SDL 3.2.0. if your SDL is older than that, it's simply not going to happen, sorry babe. π
π SEE ALSO π
Simple Directmedia Layer said hi, this is SDL 3.4.18, and the whole keyboard-grab saga lives under SDL_SetWindowKeyboardGrab(3). k bye, go grab responsibly πβ¨ππ¦πΈπ
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms