From dc16781877534e7af7c0bf68533415c065a3685d Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Fri, 26 May 2023 15:57:53 +0300 Subject: [PATCH] Move keyboard tests to keyboard handler --- client/eventsSDL/InputHandler.cpp | 10 +++------- client/eventsSDL/InputSourceKeyboard.cpp | 19 +++++++++++++++++++ client/eventsSDL/InputSourceKeyboard.h | 4 ++++ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/client/eventsSDL/InputHandler.cpp b/client/eventsSDL/InputHandler.cpp index ea318599e..4ddadd290 100644 --- a/client/eventsSDL/InputHandler.cpp +++ b/client/eventsSDL/InputHandler.cpp @@ -186,21 +186,17 @@ void InputHandler::fetchEvents() bool InputHandler::isKeyboardCtrlDown() const { -#ifdef VCMI_MAC - return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LGUI] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RGUI]; -#else - return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LCTRL] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RCTRL]; -#endif + return keyboardHandler->isKeyboardCtrlDown(); } bool InputHandler::isKeyboardAltDown() const { - return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LALT] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RALT]; + return keyboardHandler->isKeyboardAltDown(); } bool InputHandler::isKeyboardShiftDown() const { - return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LSHIFT] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RSHIFT]; + return keyboardHandler->isKeyboardShiftDown(); } void InputHandler::moveCursorPosition(const Point & distance) diff --git a/client/eventsSDL/InputSourceKeyboard.cpp b/client/eventsSDL/InputSourceKeyboard.cpp index 699ad81a9..adce3271b 100644 --- a/client/eventsSDL/InputSourceKeyboard.cpp +++ b/client/eventsSDL/InputSourceKeyboard.cpp @@ -83,3 +83,22 @@ void InputSourceKeyboard::handleEventKeyUp(const SDL_KeyboardEvent & key) GH.events().dispatchShortcutReleased(shortcutsVector); } + +bool InputSourceKeyboard::isKeyboardCtrlDown() const +{ +#ifdef VCMI_MAC + return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LGUI] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RGUI]; +#else + return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LCTRL] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RCTRL]; +#endif +} + +bool InputSourceKeyboard::isKeyboardAltDown() const +{ + return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LALT] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RALT]; +} + +bool InputSourceKeyboard::isKeyboardShiftDown() const +{ + return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LSHIFT] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RSHIFT]; +} diff --git a/client/eventsSDL/InputSourceKeyboard.h b/client/eventsSDL/InputSourceKeyboard.h index 9e4fdb80a..775318701 100644 --- a/client/eventsSDL/InputSourceKeyboard.h +++ b/client/eventsSDL/InputSourceKeyboard.h @@ -20,4 +20,8 @@ public: void handleEventKeyDown(const SDL_KeyboardEvent & current); void handleEventKeyUp(const SDL_KeyboardEvent & current); + + bool isKeyboardAltDown() const; + bool isKeyboardCtrlDown() const; + bool isKeyboardShiftDown() const; };