Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}

Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading