diff --git a/OpenRA.Mods.Common/Widgets/HotkeyEntryWidget.cs b/OpenRA.Mods.Common/Widgets/HotkeyEntryWidget.cs index 53ea2482da..cd29a6a60b 100644 --- a/OpenRA.Mods.Common/Widgets/HotkeyEntryWidget.cs +++ b/OpenRA.Mods.Common/Widgets/HotkeyEntryWidget.cs @@ -24,6 +24,7 @@ namespace OpenRA.Mods.Common.Widgets public int LeftMargin = 5; public int RightMargin = 5; + public Action OnEscKey = () => { }; public Action OnLoseFocus = () => { }; public Func IsDisabled = () => false; @@ -86,7 +87,8 @@ namespace OpenRA.Mods.Common.Widgets Keycode.RSHIFT, Keycode.LSHIFT, Keycode.RCTRL, Keycode.LCTRL, Keycode.RALT, Keycode.LALT, - Keycode.RGUI, Keycode.LGUI + Keycode.RGUI, Keycode.LGUI, + Keycode.RETURN, Keycode.KP_ENTER }; public override bool HandleKeyPress(KeyInput e) @@ -97,8 +99,16 @@ namespace OpenRA.Mods.Common.Widgets if (!HasKeyboardFocus || IgnoreKeys.Contains(e.Key)) return false; - if (e.Key != Keycode.ESCAPE && e.Key != Keycode.RETURN && e.Key != Keycode.KP_ENTER) - Key = Hotkey.FromKeyInput(e); + switch (e.Key) + { + case Keycode.ESCAPE: + OnEscKey(); + break; + + default: + Key = Hotkey.FromKeyInput(e); + break; + } YieldKeyboardFocus(); diff --git a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs index e563ae6dc7..2e104069f2 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs @@ -1060,6 +1060,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic hotkeyEntryWidget = panel.Get("HOTKEY_ENTRY"); hotkeyEntryWidget.IsValid = () => isHotkeyValid; hotkeyEntryWidget.OnLoseFocus = ValidateHotkey; + hotkeyEntryWidget.OnEscKey = () => + { + hotkeyEntryWidget.Key = modData.Hotkeys[selectedHotkeyDefinition.Name].GetValue(); + }; } void ValidateHotkey() @@ -1070,6 +1074,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (isHotkeyValid) SaveHotkey(); + else + hotkeyEntryWidget.TakeKeyboardFocus(); } void SaveHotkey()