BepInEx / BepInEx.ConfigurationManager

Plugin configuration manager for BepInEx
https://www.patreon.com/ManlyMarco
GNU Lesser General Public License v3.0
227 stars 54 forks source link

[QoL] Press F1 Again to Close #86

Closed ryanburst closed 5 months ago

ryanburst commented 5 months ago

Could pressing F1 when the Config Manager is open, close it again? From what I can see you can only use the Close button and there is not a keyboard shortcut for closing.

Edit After some quick poking around, I can see that it should already do this.

https://github.com/BepInEx/BepInEx.ConfigurationManager/blob/a6c7d75566b6df411db90e04277ad1bd96231799/ConfigurationManager.Shared/ConfigurationManager.cs#L690-L697

It still doesn't work, so does this mean OverrideHotKey is getting set to true and it's returning early?

ManlyMarco commented 5 months ago

It won't work because the search box is focused by default. Unity makes text boxes eat all input. If the box is unfocused the hotkey should work fine.

You can also click anywhere outside the window to close it.

ryanburst commented 5 months ago

Could you add a key binding to the search box or check Input? I'm not as familiar with Unity, so I could be way off base here, but something like this:

private void Update
{
  // ...
  if (_keybind.Value.IsDown() || Input.GetKeyDown(_keybind.Value))
  {
    DisplayingWindow = !DisplayingWindow;
  }
}
toebeann commented 5 months ago

Could you add a key binding to the search box or check Input? I'm not as familiar with Unity, so I could be way off base here, but something like this:

private void Update
{
  // ...
  if (_keybind.Value.IsDown() || Input.GetKeyDown(_keybind.Value))
  {
    DisplayingWindow = !DisplayingWindow;
  }
}

The IsDown() method of BepInEx's KeyboardShortcut instance value is already checking whether every key of the configured keybind (which can be multiple keys) is down with the relevant Unity input engine (depends on the game). The fix you are suggesting would be redundant if it were valid C#, which it isn't.

The reason it doesn't work is as @ManlyMarco says. When the text box is focused, Unity is swallowing all key presses, meaning it is impossible to detect them using Unity APIs.

Technically, it would be possible to work around it by going low level and listening to keyboard inputs directly - without using Unity's APIs - but that's not a recommended practice, and if I were ManlyMarco I wouldn't bother. Simply not worth the headache. User can simply click outside the window, or unfocus the text box and then the keybind will work.

ryanburst commented 5 months ago

No worries, like I said, I don't really know Unity. I definitely wouldn't want to do something so complex for something so trivial. Thanks for the feedback.