Give priority of keybinds with special keys

Stop searching if found match.
This commit is contained in:
somehussar committed 2025-12-19 23:08:37 +01:00
1 parent 00eefb0887
commit 3568fb8a86
2 files changed
+33 -2

No files matched your search

@@ -8,7 +8,7 @@ import org.lwjgl.input.Mouse;
import java.util.function.Consumer;
public class KeyPreset {
public class KeyPreset implements Comparable<KeyPreset> {
/**
* @field SINGLE_PRESS => on releasing before 5 ticks press time
* @field PRESS_RELEASE => on pressing and releasing
@@ -148,6 +148,26 @@ public class KeyPreset {
return false;
}
@Override
public int compareTo(KeyPreset o) {
int mySpecialCount = getSpecialKeyCount(this);
int otherSpecialCount = getSpecialKeyCount(o);
return mySpecialCount - otherSpecialCount;
}
private static int getSpecialKeyCount(KeyPreset preset) {
int res = 0;
if (preset.hasAlt())
res += 1;
if (preset.hasCtrl())
res += 1;
if (preset.hasShift())
res += 1;
return res;
}
public static class KeyState {
public int keyCode = -1;