Skip to content

Add hint for blocking win key when using raw keyboard #13066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions include/SDL3/SDL_hints.h
Original file line number Diff line number Diff line change
Expand Up @@ -4128,6 +4128,20 @@ extern "C" {
*/
#define SDL_HINT_WINDOWS_RAW_KEYBOARD "SDL_WINDOWS_RAW_KEYBOARD"

/**
* A variable controlling whether to block hotkeys when raw keyboard events are enabled.
*
* The variable can be set to the following values:
*
* - "0": Hotkeys are not blocked. (default)
* - "1": Hotkeys are blocked.
*
* This hint must be set before SDL is initialized.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible to make this hint apply dynamically: just restart the raw input thread / re-register the devices. Having it dynamic would make it more useful, as games could enable windows hotkeys when in menus or when paused, but disable it when in active gameplay.

*
* \since This hint is available since SDL 3.2.16.
*/
#define SDL_HINT_WINDOWS_RAW_KEYBOARD_NOHOTKEY "SDL_WINDOWS_RAW_KEYBOARD_NOHOTKEY"

/**
* A variable controlling whether SDL uses Kernel Semaphores on Windows.
*
Expand Down
2 changes: 1 addition & 1 deletion src/video/windows/SDL_windowsrawinput.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static DWORD WINAPI WIN_RawInputThread(LPVOID param)
if (data->flags & ENABLE_RAW_KEYBOARD_INPUT) {
devices[count].usUsagePage = USB_USAGEPAGE_GENERIC_DESKTOP;
devices[count].usUsage = USB_USAGE_GENERIC_KEYBOARD;
devices[count].dwFlags = 0;
devices[count].dwFlags = SDL_GetHintBoolean(SDL_HINT_WINDOWS_RAW_KEYBOARD_NOHOTKEY) ? 0x200 : 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use RIDEV_NOHOTKEYS instead of a magic value.

devices[count].hwndTarget = window;
++count;
}
Expand Down
Loading