diff options
-rw-r--r-- | docs/release-notes.md | 1 | ||||
-rw-r--r-- | src/SMAPI/Framework/SGame.cs | 22 |
2 files changed, 14 insertions, 9 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md index 723cc540..2840798d 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -13,6 +13,7 @@ * Added support for `ISemanticVersion` in JSON models. * Fixed deadlock in rare cases when injecting a file with an asset loader. * Fixed unhelpful error when a mod exposes a non-public API. + * Fixed input events being raised for keyboard buttons when a textbox is receiving input. * For SMAPI developers: * Overhauled mod DB format to be more concise, reduce the memory footprint, and support versioning/defaulting more fields. 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)) { |