diff --git a/OpenRA.Game/Widgets/ButtonWidget.cs b/OpenRA.Game/Widgets/ButtonWidget.cs index 32a9672f74..9f72bca85f 100644 --- a/OpenRA.Game/Widgets/ButtonWidget.cs +++ b/OpenRA.Game/Widgets/ButtonWidget.cs @@ -25,12 +25,14 @@ namespace OpenRA.Widgets public Func GetText; public Func IsDisabled = () => false; public Action OnClick = () => {}; + public Action OnKeyPress = _ => {}; public ButtonWidget() : base() { GetText = () => { return Text; }; OnMouseUp = mi => { if (!IsDisabled()) OnClick(); return true; }; + OnKeyPress = _ => OnClick(); } protected ButtonWidget(ButtonWidget widget) @@ -42,6 +44,7 @@ namespace OpenRA.Widgets VisualHeight = widget.VisualHeight; GetText = widget.GetText; OnMouseUp = mi => { if (!IsDisabled()) OnClick(); return true; }; + OnKeyPress = _ => OnClick(); } public override bool LoseFocus(MouseInput mi) @@ -52,11 +55,12 @@ namespace OpenRA.Widgets public override bool HandleKeyPressInner(KeyInput e) { - if (e.KeyName != Key || e.Modifiers != Modifiers.None || e.Event != KeyInputEvent.Down) + if (e.KeyName != Key || e.Event != KeyInputEvent.Down) return false; if (!IsDisabled()) - OnClick(); + OnKeyPress(e); + return true; } diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index f8cd20467b..22cde10138 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -41,7 +41,6 @@ namespace OpenRA.Widgets public Func OnMouseDown = mi => false; public Func OnMouseUp = mi => false; public Action OnMouseMove = mi => { }; - public Func OnKeyPress = e => false; public Func IsVisible; @@ -70,7 +69,6 @@ namespace OpenRA.Widgets OnMouseDown = widget.OnMouseDown; OnMouseUp = widget.OnMouseUp; OnMouseMove = widget.OnMouseMove; - OnKeyPress = widget.OnKeyPress; IsVisible = widget.IsVisible; @@ -252,9 +250,6 @@ namespace OpenRA.Widgets // Do any widgety behavior (enter text etc) var handled = HandleKeyPressInner(e); - // Apply any special logic added by event handlers; they return true if they caught the input - if (OnKeyPress(e)) return true; - return handled; }