UnlimitedHugs / RimworldHugsLib

A lightweight shared library for Rimworld modding.
Other
244 stars 59 forks source link

TextField Focus prevents restart hotkey ; use KeyBindingDef.IsDownEvent #95

Open alextd opened 1 year ago

alextd commented 1 year ago

Apparently with Unity for some reason, when a GUI.TextField is focused, any Input.GetKeyDown returns false.

HugsLibs is using KeyBindingDef.JustPressed that does GetKeyDown in OnGUI so I think it should use IsDownEvent to catch these key presses via an Event.

I also think after a little searching that GetKeyDown is for Unity mono behavior Update() and the events are for OnGUI() so this change is probably just more correct in any case?

So yah I have a textfield set up that explicitly ignores certain key events, does not call textfield for that, but the existence of the text field focus is the problem. Even if another window is in front and text cannot be entered, HugsLib still doesn't process keys with that focuses textinput. I end up opening the animals tab because I bound the restart hotkey to F5.

UnlimitedHugs commented 2 months ago

Nice catch, and valid observations about OnGUI. I have given your solution a try, but it seems like KeyDown events are not getting sent at all when an input field is focused.

alextd commented 2 months ago

Of course I hardly remember this, what seems to be my conclusion from debugging some odd problem

If it's not a simple fix ... nevermind then.

UnlimitedHugs commented 2 months ago

It's still relevant as of today so I'll keep this open in case someone suggests with a viable fix.