From 033015066650d4bd67a7df0a7f7addf4c6edf617 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 18 Feb 2018 22:40:20 -0500 Subject: suppress keyboard events when a textbox is focused (#445) --- src/SMAPI/Framework/SGame.cs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/SMAPI/Framework/SGame.cs') diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs index e82ee778..f080f3c5 100644 --- a/src/SMAPI/Framework/SGame.cs +++ b/src/SMAPI/Framework/SGame.cs @@ -256,7 +256,7 @@ namespace StardewModdingAPI.Framework this.Monitor.Log("Context: before save creation.", LogLevel.Trace); SaveEvents.InvokeBeforeCreate(this.Monitor); } - + // raise before-save if (Context.IsWorldReady && !this.IsBetweenSaveEvents) { @@ -386,20 +386,23 @@ namespace StardewModdingAPI.Framework } // raise input events + bool isTextboxReceiving = Game1.keyboardDispatcher?.Subscriber?.Selected == true; foreach (var pair in inputState.ActiveButtons) { SButton button = pair.Key; InputStatus status = pair.Value; + bool isKeyboard = button.TryGetKeyboard(out Keys keyboardKey); if (status == InputStatus.Pressed) { - InputEvents.InvokeButtonPressed(this.Monitor, button, cursor, button.IsActionButton(), button.IsUseToolButton()); + if (!isTextboxReceiving || !isKeyboard) + InputEvents.InvokeButtonPressed(this.Monitor, button, cursor, button.IsActionButton(), button.IsUseToolButton()); // legacy events - if (button.TryGetKeyboard(out Keys key)) + if (isKeyboard) { - if (key != Keys.None) - ControlEvents.InvokeKeyPressed(this.Monitor, key); + if (!isTextboxReceiving && keyboardKey != Keys.None) + ControlEvents.InvokeKeyPressed(this.Monitor, keyboardKey); } else if (button.TryGetController(out Buttons controllerButton)) { @@ -411,13 +414,14 @@ namespace StardewModdingAPI.Framework } else if (status == InputStatus.Released) { - InputEvents.InvokeButtonReleased(this.Monitor, button, cursor, button.IsActionButton(), button.IsUseToolButton()); + if (!isTextboxReceiving || !isKeyboard) + InputEvents.InvokeButtonReleased(this.Monitor, button, cursor, button.IsActionButton(), button.IsUseToolButton()); // legacy events - if (button.TryGetKeyboard(out Keys key)) + if (isKeyboard) { - if (key != Keys.None) - ControlEvents.InvokeKeyReleased(this.Monitor, key); + if (!isTextboxReceiving && keyboardKey != Keys.None) + ControlEvents.InvokeKeyReleased(this.Monitor, keyboardKey); } else if (button.TryGetController(out Buttons controllerButton)) { -- cgit