1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-17 01:32:21 +02:00

Move keyboard tests to keyboard handler

This commit is contained in:
Ivan Savenko
2023-05-26 15:57:53 +03:00
parent 503bd1dd66
commit dc16781877
3 changed files with 26 additions and 7 deletions

View File

@ -186,21 +186,17 @@ void InputHandler::fetchEvents()
bool InputHandler::isKeyboardCtrlDown() const bool InputHandler::isKeyboardCtrlDown() const
{ {
#ifdef VCMI_MAC return keyboardHandler->isKeyboardCtrlDown();
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 InputHandler::isKeyboardAltDown() const bool InputHandler::isKeyboardAltDown() const
{ {
return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LALT] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RALT]; return keyboardHandler->isKeyboardAltDown();
} }
bool InputHandler::isKeyboardShiftDown() const 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) void InputHandler::moveCursorPosition(const Point & distance)

View File

@ -83,3 +83,22 @@ void InputSourceKeyboard::handleEventKeyUp(const SDL_KeyboardEvent & key)
GH.events().dispatchShortcutReleased(shortcutsVector); 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];
}

View File

@ -20,4 +20,8 @@ public:
void handleEventKeyDown(const SDL_KeyboardEvent & current); void handleEventKeyDown(const SDL_KeyboardEvent & current);
void handleEventKeyUp(const SDL_KeyboardEvent & current); void handleEventKeyUp(const SDL_KeyboardEvent & current);
bool isKeyboardAltDown() const;
bool isKeyboardCtrlDown() const;
bool isKeyboardShiftDown() const;
}; };