Skip to content

Commit 1ccf4e9

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

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-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 can be set anytime.
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#define ENABLE_RAW_MOUSE_INPUT 0x01
3535
#define ENABLE_RAW_KEYBOARD_INPUT 0x02
36+
#define RAW_KEYBOARD_FLAG_NOHOTKEYS 0x00000200
3637

3738
typedef struct
3839
{
@@ -78,6 +79,9 @@ static DWORD WINAPI WIN_RawInputThread(LPVOID param)
7879
devices[count].usUsagePage = USB_USAGEPAGE_GENERIC_DESKTOP;
7980
devices[count].usUsage = USB_USAGE_GENERIC_KEYBOARD;
8081
devices[count].dwFlags = 0;
82+
if (data->flags & RAW_KEYBOARD_FLAG_NOHOTKEYS) {
83+
devices[count].dwFlags |= RIDEV_NOHOTKEYS;
84+
}
8185
devices[count].hwndTarget = window;
8286
++count;
8387
}
@@ -198,6 +202,9 @@ static bool WIN_UpdateRawInputEnabled(SDL_VideoDevice *_this)
198202
}
199203
if (data->raw_keyboard_enabled) {
200204
flags |= ENABLE_RAW_KEYBOARD_INPUT;
205+
if (data->raw_keyboard_flag_nohotkeys) {
206+
flags |= RAW_KEYBOARD_FLAG_NOHOTKEYS;
207+
}
201208
}
202209
if (flags != data->raw_input_enabled) {
203210
if (WIN_SetRawInputEnabled(_this, flags)) {

src/video/windows/SDL_windowsvideo.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ static void SDLCALL UpdateWindowsRawKeyboard(void *userdata, const char *name, c
6262
WIN_SetRawKeyboardEnabled(_this, enabled);
6363
}
6464

65+
static void SDLCALL UpdateWindowsRawKeyboardNoHotkeys(void *userdata, const char *name, const char *oldValue, const char *newValue)
66+
{
67+
SDL_VideoDevice *_this = (SDL_VideoDevice *)userdata;
68+
SDL_VideoData *data = _this->internal;
69+
data->raw_keyboard_flag_nohotkeys = SDL_GetStringBoolean(newValue, false);
70+
WIN_SetRawKeyboardEnabled(_this, data->raw_keyboard_enabled);
71+
}
72+
73+
6574
static void SDLCALL UpdateWindowsEnableMessageLoop(void *userdata, const char *name, const char *oldValue, const char *newValue)
6675
{
6776
g_WindowsEnableMessageLoop = SDL_GetStringBoolean(newValue, true);
@@ -550,6 +559,7 @@ static bool WIN_VideoInit(SDL_VideoDevice *_this)
550559
#endif
551560

552561
SDL_AddHintCallback(SDL_HINT_WINDOWS_RAW_KEYBOARD, UpdateWindowsRawKeyboard, _this);
562+
SDL_AddHintCallback(SDL_HINT_WINDOWS_RAW_KEYBOARD_NOHOTKEYS, UpdateWindowsRawKeyboardNoHotkeys, _this);
553563
SDL_AddHintCallback(SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP, UpdateWindowsEnableMessageLoop, NULL);
554564
SDL_AddHintCallback(SDL_HINT_WINDOWS_ENABLE_MENU_MNEMONICS, UpdateWindowsEnableMenuMnemonics, NULL);
555565
SDL_AddHintCallback(SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN, UpdateWindowFrameUsableWhileCursorHidden, NULL);
@@ -569,6 +579,7 @@ void WIN_VideoQuit(SDL_VideoDevice *_this)
569579
SDL_VideoData *data = _this->internal;
570580

571581
SDL_RemoveHintCallback(SDL_HINT_WINDOWS_RAW_KEYBOARD, UpdateWindowsRawKeyboard, _this);
582+
SDL_RemoveHintCallback(SDL_HINT_WINDOWS_RAW_KEYBOARD_NOHOTKEYS, UpdateWindowsRawKeyboardNoHotkeys, _this);
572583
SDL_RemoveHintCallback(SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP, UpdateWindowsEnableMessageLoop, NULL);
573584
SDL_RemoveHintCallback(SDL_HINT_WINDOWS_ENABLE_MENU_MNEMONICS, UpdateWindowsEnableMenuMnemonics, NULL);
574585
SDL_RemoveHintCallback(SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN, UpdateWindowFrameUsableWhileCursorHidden, NULL);

src/video/windows/SDL_windowsvideo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ struct SDL_VideoData
486486
SDL_Point last_raw_mouse_position;
487487
bool raw_mouse_enabled;
488488
bool raw_keyboard_enabled;
489+
bool raw_keyboard_flag_nohotkeys;
489490
bool pending_E1_key_sequence;
490491
Uint32 raw_input_enabled;
491492

0 commit comments

Comments
 (0)