From 5cc99564a782590b43f5e76a83690e9b9eab8f9b Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Mon, 1 Nov 2021 20:42:29 -0700 Subject: [PATCH] Updated fix for Bug #934. SDL1 and SDL2 have slightly different behavior regarding detection of the NUM LOCK key. Both branches should now interpret keypad input when in text-input mode as only text when NUM LOCK is on. --- sc2/src/libs/input/sdl/input.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/sc2/src/libs/input/sdl/input.c b/sc2/src/libs/input/sdl/input.c index bff17aa56..fabecd3e1 100644 --- a/sc2/src/libs/input/sdl/input.c +++ b/sc2/src/libs/input/sdl/input.c @@ -361,10 +361,9 @@ is_numpad_char_event (const SDL_Event *Event) { return in_character_mode && (Event->type == SDL_KEYDOWN || Event->type == SDL_KEYUP) && - (Event->key.keysym.mod & KMOD_NUM) && /* NumLock is ON */ Event->key.keysym.unicode > 0 && /* Printable char */ Event->key.keysym.sym >= SDLK_KP0 && /* Keypad key */ - Event->key.keysym.sym <= SDLK_KP_PLUS; + Event->key.keysym.sym <= SDLK_KP_PERIOD; } void @@ -427,6 +426,17 @@ ProcessInputEvent (const SDL_Event *Event) } } #else +static inline int +is_numpad_char_event (const SDL_Event *Event) +{ + return in_character_mode && + (Event->type == SDL_KEYDOWN || Event->type == SDL_KEYUP) && + (Event->key.keysym.mod & KMOD_NUM) && /* Numlock on */ + Event->key.keysym.sym >= SDLK_KP_1 && /* Keypad key */ + Event->key.keysym.sym <= SDLK_KP_PERIOD; + /* Note that in the SDL2 enumeration 0 comes after 9 and before period */ +} + void ProcessInputEvent (const SDL_Event *Event) { @@ -447,8 +457,10 @@ ProcessInputEvent (const SDL_Event *Event) SDL_StopTextInput (); } - /* TODO: Block numpad input when NUM_LOCK is on */ - VControl_HandleEvent (Event); + if (!is_numpad_char_event(Event)) + { + VControl_HandleEvent (Event); + } if (Event->type == SDL_TEXTINPUT) {