Suppress keyboard events when textbox has focus
Entoarox opened this issue ยท 4 comments
While text-input is being handled, keyboard events are still being processed by SMAPI.
This means any mod that listens for keybinds even if a menu is open could essentially make it impossible for users to type certain letters, with more and more mods, thus more and more keybinds in general, this issue is only going to increase.
Already some mods cant be functionally used together because of this issue, and as SMAPI goes forward the issue will only become more prominent if nothing is done.
The easiest solution would be for SMAPI to check if text input is currently being handled (Game1.keyboardDispatcher.Listener?.Enabled==true
) and if so, prevent the default keyboard events from happening.
For the rare cases where a mod for whatever reason needs to handle keyboard events during text input, a new event can be created specifically to cater to this situation.
Fixed in develop
for the upcoming SMAPI 2.5: input events are no longer raised for keyboard buttons pressed while a textbox has focus. I tested the mods I know of with textboxes and they all work fine with the change. I don't know of any mods that need textbox events, so I didn't add any for now.
That fix caused an issue where pressing a key bound to the menu button exited the current menu, even when an input had focus (#449). SMAPI will need logic to distinguish between input keys (e.g. e
) and non-input keys (e.g. ESC
) before we do this. Since SMAPI 2.5 is past dev freeze, pushed into the backlog for a later version.
Is there a way to have this fix to ChestsAnywhere be applied to a future SMAPI so that input events aren't triggered while a text box has focus?
Pathoschild/StardewMods@d0fe6c6
This is an old ticket that doesn't really apply anymore, so I'll close it.
The input events are low-level. While they're often used for keybinds, they're also used for other purposes like intercepting buttons while typing into a textbox (e.g. to filter input to allowed characters, cancel/save the option, tab to the next field, etc). You can see that in the Chests Anywhere fix too, which only disables some input handling while a textbox is active.
Instead mods should be aware of how they're using input and in what contexts it makes sense to do so. Most mods which only use them for keybinds can just ignore input in menus/cutscenes/etc with if (!Context.IsPlayerFree) return;
.