
romangraef
Members-
Content Count
1 -
Joined
-
Last visited
Community Reputation
0 NeutralAbout romangraef
-
Rank
Tree Puncher
-
romangraef joined the community
-
[1.15.2] Keybinding won't trigger in ChestScreen
romangraef replied to henne90gen's topic in Modder Support
Disclaimer: I am not an expierenced forge dev, this is just what i found after digging through a bunch of code (aka Minecraft internals). Okay, this is just for future reference, if someone else finds this thread and tries implementing it themselves. For singular events (like an inventory sort) i think subscribing to a `GuiScreenEvent.KeyboardKeyEvent` or even just as `KeyInputEvent` and then checking for keycode and modifiers might be best, but for toggles (like holding a key to show a different UI screen) i found using InputMappings.isKeyDown better. private boolean isKeyBindDown(KeyBinding keyBinding) { if (keyBinding.isKeyDown()) return true; InputMappings.Input key = keyBinding.getKey(); int keyCode = key.getKeyCode(); // GL window handle long handle = Minecraft.getInstance().getMainWindow().getHandle(); return InputMappings.isKeyDown(handle, keyCode) && keyBinding.getKeyModifier().isActive(keyBinding.getKeyConflictContext()); } `InputMappings` is internally used by `KeyModifier#isActive` as well, so im fairly confident that this is at least a somewhat intended path. This should only work with Keyboard Keybinds and not Mousebindings, but i haven't found a way for that yet, and honestly even finding this took way to long. Short addendum after i already wrote most of this: `KeyModifier#isActive` doesn't actually check the passed `IKeyConflictContext` so one should maybe check that it is active, but i think, since this mostly concerns GUIs that should actually be already checked.