1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

Keyboard shortcuts are now loaded from config file

This commit is contained in:
Ivan Savenko
2024-04-11 21:13:26 +03:00
parent 58243ddc03
commit 16c56cf6c5
4 changed files with 170 additions and 145 deletions

View File

@@ -33,6 +33,8 @@ InputSourceKeyboard::InputSourceKeyboard()
void InputSourceKeyboard::handleEventKeyDown(const SDL_KeyboardEvent & key)
{
std::string keyName = SDL_GetKeyName(key.keysym.sym);
logGlobal->trace("keyboard: key '%s' pressed", keyName);
assert(key.state == SDL_PRESSED);
if (SDL_IsTextInputActive() == SDL_TRUE)
@@ -85,8 +87,7 @@ void InputSourceKeyboard::handleEventKeyDown(const SDL_KeyboardEvent & key)
return;
}
auto shortcutsVector = GH.shortcuts().translateKeycode(key.keysym.sym);
auto shortcutsVector = GH.shortcuts().translateKeycode(keyName);
GH.events().dispatchShortcutPressed(shortcutsVector);
}
@@ -95,6 +96,9 @@ void InputSourceKeyboard::handleEventKeyUp(const SDL_KeyboardEvent & key)
if(key.repeat != 0)
return; // ignore periodic event resends
std::string keyName = SDL_GetKeyName(key.keysym.sym);
logGlobal->trace("keyboard: key '%s' released", keyName);
if (SDL_IsTextInputActive() == SDL_TRUE)
{
if (key.keysym.sym >= ' ' && key.keysym.sym < 0x80)
@@ -103,7 +107,7 @@ void InputSourceKeyboard::handleEventKeyUp(const SDL_KeyboardEvent & key)
assert(key.state == SDL_RELEASED);
auto shortcutsVector = GH.shortcuts().translateKeycode(key.keysym.sym);
auto shortcutsVector = GH.shortcuts().translateKeycode(keyName);
GH.events().dispatchShortcutReleased(shortcutsVector);
}