From a7cfdc6edda332ba258cdfc0d19fa0e3d6b63d90 Mon Sep 17 00:00:00 2001 From: crazycat256 Date: Mon, 9 Nov 2026 18:45:01 +0100 Subject: [PATCH] Fix keyboard and mouse input collisions --- .../hud/elements/keyboard/KeyboardHud.java | 22 +++++++------------ .../systems/modules/movement/GUIMove.java | 11 +++++----- .../systems/modules/render/Freecam.java | 20 ++++++++--------- .../meteorclient/utils/misc/input/Input.java | 18 +++++++++++---- 4 files changed, 38 insertions(+), 33 deletions(-) diff --git a/src/main/java/meteordevelopment/meteorclient/systems/hud/elements/keyboard/KeyboardHud.java b/src/main/java/meteordevelopment/meteorclient/systems/hud/elements/keyboard/KeyboardHud.java index 82124b222e1..2b12fdcd123 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/hud/elements/keyboard/KeyboardHud.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/hud/elements/keyboard/KeyboardHud.java @@ -26,6 +26,7 @@ import meteordevelopment.meteorclient.systems.hud.HudElementInfo; import meteordevelopment.meteorclient.systems.hud.HudRenderer; import meteordevelopment.meteorclient.utils.misc.Keybind; +import meteordevelopment.meteorclient.utils.misc.input.Input; import meteordevelopment.meteorclient.utils.misc.input.KeyAction; import meteordevelopment.meteorclient.utils.misc.input.KeyBinds; import meteordevelopment.meteorclient.utils.render.color.Color; @@ -713,9 +714,7 @@ public boolean matches(int input, int keycode, boolean key) { } else { InputConstants.Key inputKey = ((KeyMappingAccessor) binding).meteor$getKey(); boolean isKey = inputKey.getType() != InputConstants.Type.MOUSE; - return isKey == key && inputKey.getType() == InputConstants.Type.KEYBOARD - ? keycode == inputKey.getValue() - : input == inputKey.getValue(); + return isKey == key && input == inputKey.getValue(); } } @@ -731,17 +730,12 @@ public void update(KeyAction action) { } public boolean isNativelyPressed() { - if (keybind != null) { - if (!keybind.isSet()) return false; - return keybind.isKey() - ? Type.KEYBOARD.getOrCreate(keybind.getValue()).getValue() != RELEASE - : Type.MOUSE.getOrCreate(keybind.getValue()).getValue() != RELEASE; - } else { - int key = ((KeyMappingAccessor) binding).meteor$getKey().getValue(); - return key >= 0 && key < 8 - ? Type.MOUSE.getOrCreate(key).getValue() != RELEASE - : Type.KEYBOARD.getOrCreate(key).getValue() != RELEASE; - } + InputConstants.Key key = keybind != null ? keybind.key : ((KeyMappingAccessor) binding).meteor$getKey(); + if (key.equals(InputConstants.UNKNOWN)) return false; + + return key.getType() == InputConstants.Type.MOUSE + ? Input.isButtonPressed(key.getValue()) + : InputConstants.isKeyDown(key.getValue()); } public int getCps() { diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/GUIMove.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/GUIMove.java index 89aa6418a3c..97d18ed9635 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/GUIMove.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/GUIMove.java @@ -5,6 +5,7 @@ package meteordevelopment.meteorclient.systems.modules.movement; +import com.mojang.blaze3d.platform.InputConstants; import meteordevelopment.meteorclient.events.meteor.KeyInputEvent; import meteordevelopment.meteorclient.events.meteor.MouseClickEvent; import meteordevelopment.meteorclient.events.render.Render3DEvent; @@ -130,15 +131,15 @@ public boolean disableArrows() { @EventHandler private void onKey(KeyInputEvent event) { - onInput(event.key(), event.action); + onInput(InputConstants.getKey(event.input), event.action); } @EventHandler private void onButton(MouseClickEvent event) { - onInput(event.button(), event.action); + onInput(InputConstants.Type.MOUSE.getOrCreate(event.button()), event.action); } - private void onInput(int key, KeyAction action) { + private void onInput(InputConstants.Key key, KeyAction action) { if (checkSkip()) return; pass(mc.options.keyUp, key, action); @@ -186,8 +187,8 @@ private void onRender3D(Render3DEvent event) { } } - private void pass(KeyMapping bind, int key, KeyAction action) { - if (Input.getKey(bind) != key) return; + private void pass(KeyMapping bind, InputConstants.Key key, KeyAction action) { + if (!Input.matches(bind, key)) return; if (action == KeyAction.Press) bind.setDown(true); if (action == KeyAction.Release) bind.setDown(false); } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Freecam.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Freecam.java index b397d9efb19..ce3cdeda776 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Freecam.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Freecam.java @@ -5,7 +5,7 @@ package meteordevelopment.meteorclient.systems.modules.render; - +import com.mojang.blaze3d.platform.InputConstants; import meteordevelopment.meteorclient.events.game.GameLeftEvent; import meteordevelopment.meteorclient.events.game.OpenScreenEvent; import meteordevelopment.meteorclient.events.meteor.KeyInputEvent; @@ -309,7 +309,7 @@ public void onKey(KeyInputEvent event) { if (Input.isKeyPressed(KEY_F3)) return; if (checkGuiMove()) return; - if (onInput(event.key(), event.action)) event.cancel(); + if (onInput(InputConstants.getKey(event.input), event.action)) event.cancel(); } @Nullable @@ -377,26 +377,26 @@ private void onMouseClick(MouseClickEvent event) { setGoal(); } - if (onInput(event.button(), event.action)) event.cancel(); + if (onInput(InputConstants.Type.MOUSE.getOrCreate(event.button()), event.action)) event.cancel(); } - private boolean onInput(int key, KeyAction action) { - if (Input.getKey(mc.options.keyUp) == key) { + private boolean onInput(InputConstants.Key key, KeyAction action) { + if (Input.matches(mc.options.keyUp, key)) { forward = action != KeyAction.Release; mc.options.keyUp.setDown(false); - } else if (Input.getKey(mc.options.keyDown) == key) { + } else if (Input.matches(mc.options.keyDown, key)) { backward = action != KeyAction.Release; mc.options.keyDown.setDown(false); - } else if (Input.getKey(mc.options.keyRight) == key) { + } else if (Input.matches(mc.options.keyRight, key)) { right = action != KeyAction.Release; mc.options.keyRight.setDown(false); - } else if (Input.getKey(mc.options.keyLeft) == key) { + } else if (Input.matches(mc.options.keyLeft, key)) { left = action != KeyAction.Release; mc.options.keyLeft.setDown(false); - } else if (Input.getKey(mc.options.keyJump) == key) { + } else if (Input.matches(mc.options.keyJump, key)) { up = action != KeyAction.Release; mc.options.keyJump.setDown(false); - } else if (Input.getKey(mc.options.keyShift) == key) { + } else if (Input.matches(mc.options.keyShift, key)) { down = action != KeyAction.Release; mc.options.keyShift.setDown(false); } else { diff --git a/src/main/java/meteordevelopment/meteorclient/utils/misc/input/Input.java b/src/main/java/meteordevelopment/meteorclient/utils/misc/input/Input.java index 524e0c7686f..8eecd34c62b 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/misc/input/Input.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/misc/input/Input.java @@ -38,24 +38,34 @@ public static int getKey(KeyMapping bind) { return ((KeyMappingAccessor) bind).meteor$getKey().getValue(); } + public static boolean matches(KeyMapping bind, InputConstants.Key key) { + // SDL keyboard scancodes and mouse buttons can have the same numeric value. + return ((KeyMappingAccessor) bind).meteor$getKey().equals(key); + } + public static void setKeyState(KeyMapping bind, boolean pressed) { - setKeyState(getKey(bind), pressed); + InputConstants.Key key = ((KeyMappingAccessor) bind).meteor$getKey(); + if (key.getType() == InputConstants.Type.MOUSE) setButtonState(key.getValue(), pressed); + else setKeyState(key.getValue(), pressed); } public static boolean isPressed(KeyMapping bind) { - return isKeyPressed(getKey(bind)) || isButtonPressed(getKey(bind)); + InputConstants.Key key = ((KeyMappingAccessor) bind).meteor$getKey(); + return key.getType() == InputConstants.Type.MOUSE + ? isButtonPressed(key.getValue()) + : isKeyPressed(key.getValue()); } public static boolean isKeyPressed(int key) { if (!GuiKeyEvents.canUseKeys) return false; if (key == InputConstants.UNKNOWN.getValue()) return false; - return key < keys.length && keys[key]; + return key >= 0 && key < keys.length && keys[key]; } public static boolean isButtonPressed(int button) { if (button == -1) return false; - return button < buttons.length && buttons[button]; + return button >= 0 && button < buttons.length && buttons[button]; } public static void setCursorStyle(CursorType style) {