Skip to content

Commit 6f443ff

Browse files
committed
Add hint for blocking win key when using raw keyboard
1 parent 510c7ed commit 6f443ff

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

include/SDL3/SDL_hints.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4128,6 +4128,20 @@ extern "C" {
41284128
*/
41294129
#define SDL_HINT_WINDOWS_RAW_KEYBOARD "SDL_WINDOWS_RAW_KEYBOARD"
41304130

4131+
/**
4132+
* A variable controlling whether to block hotkeys when raw keyboard events are enabled.
4133+
*
4134+
* The variable can be set to the following values:
4135+
*
4136+
* - "0": Hotkeys are not blocked. (default)
4137+
* - "1": Hotkeys are blocked.
4138+
*
4139+
* This hint must be set before SDL is initialized.
4140+
*
4141+
* \since This hint is available since SDL 3.2.22.
4142+
*/
4143+
#define SDL_HINT_WINDOWS_RAW_KEYBOARD_NOHOTKEYS "SDL_WINDOWS_RAW_KEYBOARD_NOHOTKEYS"
4144+
41314145
/**
41324146
* A variable controlling whether SDL uses Kernel Semaphores on Windows.
41334147
*

src/video/windows/SDL_windowsrawinput.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ static DWORD WINAPI WIN_RawInputThread(LPVOID param)
7878
devices[count].usUsagePage = USB_USAGEPAGE_GENERIC_DESKTOP;
7979
devices[count].usUsage = USB_USAGE_GENERIC_KEYBOARD;
8080
devices[count].dwFlags = 0;
81+
if (SDL_GetHintBoolean(SDL_HINT_WINDOWS_RAW_KEYBOARD_NOHOTKEYS, false)) {
82+
devices[count].dwFlags |= RIDEV_NOHOTKEYS;
83+
}
8184
devices[count].hwndTarget = window;
8285
++count;
8386
}

src/video/windows/SDL_windowsvideo.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ static bool WIN_VideoInit(SDL_VideoDevice *_this)
550550
#endif
551551

552552
SDL_AddHintCallback(SDL_HINT_WINDOWS_RAW_KEYBOARD, UpdateWindowsRawKeyboard, _this);
553+
SDL_AddHintCallback(SDL_HINT_WINDOWS_RAW_KEYBOARD_NOHOTKEYS, UpdateWindowsRawKeyboard, _this);
553554
SDL_AddHintCallback(SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP, UpdateWindowsEnableMessageLoop, NULL);
554555
SDL_AddHintCallback(SDL_HINT_WINDOWS_ENABLE_MENU_MNEMONICS, UpdateWindowsEnableMenuMnemonics, NULL);
555556
SDL_AddHintCallback(SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN, UpdateWindowFrameUsableWhileCursorHidden, NULL);
@@ -569,6 +570,7 @@ void WIN_VideoQuit(SDL_VideoDevice *_this)
569570
SDL_VideoData *data = _this->internal;
570571

571572
SDL_RemoveHintCallback(SDL_HINT_WINDOWS_RAW_KEYBOARD, UpdateWindowsRawKeyboard, _this);
573+
SDL_RemoveHintCallback(SDL_HINT_WINDOWS_RAW_KEYBOARD_NOHOTKEYS, UpdateWindowsRawKeyboard, _this);
572574
SDL_RemoveHintCallback(SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP, UpdateWindowsEnableMessageLoop, NULL);
573575
SDL_RemoveHintCallback(SDL_HINT_WINDOWS_ENABLE_MENU_MNEMONICS, UpdateWindowsEnableMenuMnemonics, NULL);
574576
SDL_RemoveHintCallback(SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN, UpdateWindowFrameUsableWhileCursorHidden, NULL);

0 commit comments

Comments
 (0)