Skip to content
Merged
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
20 changes: 13 additions & 7 deletions src/main/java/meteordevelopment/meteorclient/gui/WidgetScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,24 @@ public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmou
}

@Override
public boolean keyReleased(@NonNull KeyEvent input) {
public boolean keyReleased(@NonNull KeyEvent event) {
if (locked) return false;

if ((input.modifiers() == MOD_CONTROL || input.modifiers() == MOD_SUPER) && input.key() == KEY_9) {
boolean ctrl = SystemUtils.IS_OS_MAC
? Input.modsMatch(event.modifiers(), MOD_SUPER)
: Input.modsMatch(event.modifiers(), MOD_CONTROL);

if (ctrl && event.key() == KEY_9) {
debug = !debug;
return true;
}

if ((input.key() == KEY_RETURN || input.key() == KEY_NUMPADENTER) && enterAction != null) {
if ((event.key() == KEY_RETURN || event.key() == KEY_NUMPADENTER) && enterAction != null) {
enterAction.run();
return true;
}

return super.keyReleased(input);
return super.keyReleased(event);
}

@Override
Expand Down Expand Up @@ -239,10 +243,12 @@ public boolean keyPressed(@NonNull KeyEvent input) {
return true;
}

boolean control = SystemUtils.IS_OS_MAC ? input.modifiers() == MOD_SUPER : input.modifiers() == MOD_CONTROL;
boolean ctrl = SystemUtils.IS_OS_MAC
? Input.modsMatch(input.modifiers(), MOD_SUPER)
: Input.modsMatch(input.modifiers(), MOD_CONTROL);

return (control && input.key() == KEY_C && toClipboard())
|| (control && input.key() == KEY_V && fromClipboard());
return (ctrl && input.key() == KEY_C && toClipboard())
|| (ctrl && input.key() == KEY_V && fromClipboard());
}

public void keyRepeated(KeyEvent input) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.meteorclient.systems.modules.Modules;
import meteordevelopment.meteorclient.utils.misc.NbtUtils;
import meteordevelopment.meteorclient.utils.misc.input.Input;
import meteordevelopment.meteorclient.utils.render.DisplayItemUtils;
import net.minecraft.client.input.KeyEvent;
import net.minecraft.world.item.Items;
Expand Down Expand Up @@ -152,12 +153,14 @@ protected WWindow createSearch(WContainer c) {
}

@Override
public boolean keyPressed(@NonNull KeyEvent value) {
public boolean keyPressed(@NonNull KeyEvent input) {
if (locked) return false;

boolean cntrl = SystemUtils.IS_OS_MAC ? value.modifiers() == MOD_SUPER : value.modifiers() == MOD_CONTROL;
boolean ctrl = SystemUtils.IS_OS_MAC
? Input.modsMatch(input.modifiers(), MOD_SUPER)
: Input.modsMatch(input.modifiers(), MOD_CONTROL);

if (cntrl && value.key() == KEY_F) {
if (ctrl && input.key() == KEY_F) {
if (searchWindow != null) searchWindow.setExpanded(true);
if (searchTextBox != null) {
searchTextBox.setFocused(true);
Expand All @@ -167,7 +170,7 @@ public boolean keyPressed(@NonNull KeyEvent value) {
return true;
}

return super.keyPressed(value);
return super.keyPressed(input);
}

// Favorites
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import meteordevelopment.meteorclient.gui.utils.CharFilter;
import meteordevelopment.meteorclient.gui.widgets.WWidget;
import meteordevelopment.meteorclient.gui.widgets.containers.WContainer;
import meteordevelopment.meteorclient.utils.misc.input.Input;
import meteordevelopment.meteorclient.utils.render.color.Color;
import net.minecraft.client.input.CharacterEvent;
import net.minecraft.client.input.KeyEvent;
Expand Down Expand Up @@ -239,25 +240,31 @@ public boolean onMouseReleased(MouseButtonEvent click) {
public boolean onKeyPressed(KeyEvent input) {
if (!focused) return false;

boolean control = SystemUtils.IS_OS_MAC ? input.modifiers() == MOD_SUPER : input.modifiers() == MOD_CONTROL;
boolean ctrl = SystemUtils.IS_OS_MAC
? Input.modsMatch(input.modifiers(), MOD_SUPER)
: Input.modsMatch(input.modifiers(), MOD_CONTROL);

if (control && input.key() == KEY_C) {
boolean ctrlShift = SystemUtils.IS_OS_MAC
? Input.modsMatch(input.modifiers(), MOD_SUPER, MOD_SHIFT)
: Input.modsMatch(input.modifiers(), MOD_CONTROL, MOD_SHIFT);

if (ctrl && input.key() == KEY_C) {
if (cursor != selectionStart || cursor != selectionEnd) {
mc.keyboardHandler.setClipboard(text.substring(selectionStart, selectionEnd));
}
return true;
} else if (control && input.key() == KEY_X) {
} else if (ctrl && input.key() == KEY_X) {
if (cursor != selectionStart || cursor != selectionEnd) {
mc.keyboardHandler.setClipboard(text.substring(selectionStart, selectionEnd));
clearSelection();
}

return true;
} else if (control && input.key() == KEY_A) {
} else if (ctrl && input.key() == KEY_A) {
cursor = text.length();
selectionStart = 0;
selectionEnd = cursor;
} else if (input.modifiers() == ((SystemUtils.IS_OS_MAC ? MOD_SUPER : MOD_CONTROL) | MOD_SHIFT) && input.key() == KEY_A) {
} else if (ctrlShift && input.key() == KEY_A) {
resetSelection();
} else if (input.key() == KEY_RETURN || input.key() == KEY_NUMPADENTER) {
setFocused(false);
Expand Down Expand Up @@ -298,12 +305,23 @@ public boolean onKeyPressed(KeyEvent input) {
public boolean onKeyRepeated(KeyEvent input) {
if (!focused) return false;

boolean control = SystemUtils.IS_OS_MAC ? input.modifiers() == MOD_SUPER : input.modifiers() == MOD_CONTROL;
boolean shift = input.modifiers() == MOD_SHIFT;
boolean controlShift = input.modifiers() == ((SystemUtils.IS_OS_WINDOWS ? MOD_ALT : SystemUtils.IS_OS_MAC ? MOD_SUPER : MOD_CONTROL) | MOD_SHIFT);
boolean altShift = input.modifiers() == ((SystemUtils.IS_OS_WINDOWS ? MOD_CONTROL : MOD_ALT) | MOD_SHIFT);
boolean ctrl = SystemUtils.IS_OS_MAC
? Input.modsMatch(input.modifiers(), MOD_SUPER)
: Input.modsMatch(input.modifiers(), MOD_CONTROL);

boolean shift = Input.modsMatch(input.modifiers(), MOD_SHIFT);

// modifier for jumping to the start/end of the text box, and the one for jumping by word
int lineMod = SystemUtils.IS_OS_WINDOWS ? MOD_ALT : SystemUtils.IS_OS_MAC ? MOD_SUPER : MOD_CONTROL;
int wordMod = SystemUtils.IS_OS_WINDOWS ? MOD_CONTROL : MOD_ALT;

boolean line = Input.modsMatch(input.modifiers(), lineMod);
boolean word = Input.modsMatch(input.modifiers(), wordMod);
boolean ctrlShift = Input.modsMatch(input.modifiers(), lineMod, MOD_SHIFT);
boolean altShift = Input.modsMatch(input.modifiers(), wordMod, MOD_SHIFT);
boolean noMods = Input.modsMatch(input.modifiers());

if (control && input.key() == KEY_V) {
if (ctrl && input.key() == KEY_V) {
clearSelection();

String preText = text;
Expand Down Expand Up @@ -331,9 +349,9 @@ public boolean onKeyRepeated(KeyEvent input) {
if (cursor > 0 && cursor == selectionStart && cursor == selectionEnd) {
String preText = text;

int count = (input.modifiers() == (SystemUtils.IS_OS_WINDOWS ? MOD_ALT : SystemUtils.IS_OS_MAC ? MOD_SUPER : MOD_CONTROL))
int count = line
? cursor
: (input.modifiers() == (SystemUtils.IS_OS_WINDOWS ? MOD_CONTROL : MOD_ALT))
: word
? countToNextSpace(true)
: 1;

Expand All @@ -352,9 +370,9 @@ public boolean onKeyRepeated(KeyEvent input) {
if (cursor < text.length()) {
String preText = text;

int count = input.modifiers() == (SystemUtils.IS_OS_WINDOWS ? MOD_ALT : SystemUtils.IS_OS_MAC ? MOD_SUPER : MOD_CONTROL)
int count = line
? text.length() - cursor
: (input.modifiers() == (SystemUtils.IS_OS_WINDOWS ? MOD_CONTROL : MOD_ALT))
: word
? countToNextSpace(false)
: 1;

Expand All @@ -369,12 +387,12 @@ public boolean onKeyRepeated(KeyEvent input) {
} else if (input.key() == KEY_LEFT) {
if (cursor > 0) {
// sets the cursor to just after the next leftmost space
if (input.modifiers() == (SystemUtils.IS_OS_WINDOWS ? MOD_CONTROL : MOD_ALT)) {
if (word) {
cursor -= countToNextSpace(true);
resetSelection();
}
// sets the cursor to the beginning of the text box
else if (input.modifiers() == (SystemUtils.IS_OS_WINDOWS ? MOD_ALT : SystemUtils.IS_OS_MAC ? MOD_SUPER : MOD_CONTROL)) {
else if (line) {
cursor = 0;
resetSelection();
}
Expand All @@ -393,7 +411,7 @@ else if (altShift) {
}
}
// sets the selection to the beginning of the text box
else if (controlShift) {
else if (ctrlShift) {
if (cursor == selectionEnd && cursor != selectionStart) {
selectionEnd = selectionStart;
}
Expand Down Expand Up @@ -423,7 +441,7 @@ else if (shift) {
}

cursorChanged();
} else if (selectionStart != selectionEnd && selectionStart == 0 && input.modifiers() == 0) {
} else if (selectionStart != selectionEnd && selectionStart == 0 && noMods) {
cursor = 0;
resetSelection();
cursorChanged();
Expand All @@ -433,12 +451,12 @@ else if (shift) {
} else if (input.key() == KEY_RIGHT) {
if (cursor < text.length()) {
// sets the cursor to just before the next rightmost space
if (input.modifiers() == (SystemUtils.IS_OS_WINDOWS ? MOD_CONTROL : MOD_ALT)) {
if (word) {
cursor += countToNextSpace(false);
resetSelection();
}
// sets the cursor to the end of the text box
else if (input.modifiers() == (SystemUtils.IS_OS_WINDOWS ? MOD_ALT : SystemUtils.IS_OS_MAC ? MOD_SUPER : MOD_CONTROL)) {
else if (line) {
cursor = text.length();
resetSelection();
}
Expand All @@ -457,7 +475,7 @@ else if (altShift) {
}
}
// sets the selection to the end of the text box
else if (controlShift) {
else if (ctrlShift) {
if (cursor == selectionStart && cursor != selectionEnd) {
selectionStart = selectionEnd;
}
Expand Down Expand Up @@ -486,7 +504,7 @@ else if (shift) {
}

cursorChanged();
} else if (selectionStart != selectionEnd && selectionEnd == text.length() && input.modifiers() == 0) {
} else if (selectionStart != selectionEnd && selectionEnd == text.length() && noMods) {
cursor = text.length();
resetSelection();
cursorChanged();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public class Input {
private static final boolean[] keys = new boolean[512];
private static final boolean[] buttons = new boolean[16];

private static final int MOD_KEYS = InputConstants.MOD_SHIFT
| InputConstants.MOD_CONTROL
| InputConstants.MOD_ALT
| InputConstants.MOD_SUPER;

private static CursorType lastCursorStyle = CursorTypes.ARROW;

private Input() {
Expand Down Expand Up @@ -69,4 +74,18 @@ public static int getModifier(int key) {
default -> 0;
};
}

public static boolean modsMatch(int currentMods, int... desiredMods) {
int desiredMask = 0;

for (int mod : desiredMods) {
// a required modifier isn't held
if ((currentMods & mod) == 0) return false;

desiredMask |= mod;
}

// nothing extra is held, discounting capslock & numlock
return (currentMods & MOD_KEYS & ~desiredMask) == 0;
}
}
Loading