فهرست منبع

Merge pull request #3905 from IvanSavenko/fix_shortcuts

[1.5.0] Fix keyboard shortcuts
Ivan Savenko 1 سال پیش
والد
کامیت
6a1477838d
3فایلهای تغییر یافته به همراه22 افزوده شده و 1 حذف شده
  1. 16 1
      client/eventsSDL/InputSourceKeyboard.cpp
  2. 1 0
      client/eventsSDL/InputSourceKeyboard.h
  3. 5 0
      config/shortcutsConfig.json

+ 16 - 1
client/eventsSDL/InputSourceKeyboard.cpp

@@ -32,9 +32,24 @@ InputSourceKeyboard::InputSourceKeyboard()
 #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)
 {
-	std::string keyName = SDL_GetKeyName(key.keysym.sym);
+	std::string keyName = getKeyNameWithModifiers(SDL_GetKeyName(key.keysym.sym));
 	logGlobal->trace("keyboard: key '%s' pressed", keyName);
 	assert(key.state == SDL_PRESSED);
 

+ 1 - 0
client/eventsSDL/InputSourceKeyboard.h

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

+ 5 - 0
config/shortcutsConfig.json

@@ -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
 //
 // 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" : {
 		"globalAccept":             [ "Return", "Keypad Enter"],
@@ -112,6 +113,10 @@
 		"battleTacticsEnd":         [ "Return", "Keypad Enter"],
 		"battleToggleHeroesStats":  [],
 		"battleSelectAction":       "S",
+		"lobbyActivateInterface":   "Ctrl+Tab",
+		"spectateTrackHero":        "F5",
+		"spectateSkipBattle":       "F7",
+		"spectateSkipBattleResult": "F8",
 		"townOpenTavern":           "T",
 		"townSwapArmies":           "Space",
 		"recruitmentMax":           "End",