1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Added option to configure key modifiers (Alt, Shift, Ctrl). Fixes lobby

hotkey activation.
This commit is contained in:
Ivan Savenko 2024-05-07 08:55:41 +00:00
parent 4949b98ed3
commit ffc207888b
3 changed files with 22 additions and 1 deletions

View File

@ -32,9 +32,24 @@ InputSourceKeyboard::InputSourceKeyboard()
#endif #endif
} }
std::string InputSourceKeyboard::getKeyNameWithModifiers(const std::string & keyName) const
{
std::string result;
if (isKeyboardCtrlDown())
result += "Ctrl+";
if (isKeyboardAltDown())
result += "Alt+";
if (isKeyboardShiftDown())
result += "Shift+";
result += keyName;
return result;
}
void InputSourceKeyboard::handleEventKeyDown(const SDL_KeyboardEvent & key) void InputSourceKeyboard::handleEventKeyDown(const SDL_KeyboardEvent & key)
{ {
std::string keyName = SDL_GetKeyName(key.keysym.sym); std::string keyName = getKeyNameWithModifiers(SDL_GetKeyName(key.keysym.sym));
logGlobal->trace("keyboard: key '%s' pressed", keyName); logGlobal->trace("keyboard: key '%s' pressed", keyName);
assert(key.state == SDL_PRESSED); assert(key.state == SDL_PRESSED);

View File

@ -15,6 +15,7 @@ struct SDL_KeyboardEvent;
/// Class that handles keyboard input from SDL events /// Class that handles keyboard input from SDL events
class InputSourceKeyboard class InputSourceKeyboard
{ {
std::string getKeyNameWithModifiers(const std::string & keyName) const;
public: public:
InputSourceKeyboard(); InputSourceKeyboard();

View File

@ -4,6 +4,7 @@
// For players (Linux): create file ~/.config/vcmi/shortcutsConfig.json (or ~/.var/app/eu.vcmi.VCMI/config for Flatpak) to modify this set // For players (Linux): create file ~/.config/vcmi/shortcutsConfig.json (or ~/.var/app/eu.vcmi.VCMI/config for Flatpak) to modify this set
// //
// When creating your own config, you can remove all hotkeys that you have not changed and game will read them from this file // When creating your own config, you can remove all hotkeys that you have not changed and game will read them from this file
// It is possible to add modifiers to keys: Ctrl, Shift, or Alt. For example, "Ctrl+Tab" hotkey will only activate if Ctrl is pressed
{ {
"keyboard" : { "keyboard" : {
"globalAccept": [ "Return", "Keypad Enter"], "globalAccept": [ "Return", "Keypad Enter"],
@ -112,6 +113,10 @@
"battleTacticsEnd": [ "Return", "Keypad Enter"], "battleTacticsEnd": [ "Return", "Keypad Enter"],
"battleToggleHeroesStats": [], "battleToggleHeroesStats": [],
"battleSelectAction": "S", "battleSelectAction": "S",
"lobbyActivateInterface": "Ctrl+Tab",
"spectateTrackHero": "F5",
"spectateSkipBattle": "F7",
"spectateSkipBattleResult": "F8",
"townOpenTavern": "T", "townOpenTavern": "T",
"townSwapArmies": "Space", "townSwapArmies": "Space",
"recruitmentMax": "End", "recruitmentMax": "End",