Improved KeyPreset.setDown logic

This commit is contained in:
bigguy345 committed 2025-12-19 12:49:05 +02:00
1 parent cb09deb495
commit d52e82bb5b
2 files changed
+15 -11

No files matched your search

@@ -20,4 +20,5 @@ public class KeyEvent {
public boolean isHold() { return is(KeyPreset.PressType.HOLD); }
public boolean isRelease() { return is(KeyPreset.PressType.RELEASE); }
public boolean isSinglePress() { return is(KeyPreset.PressType.SINGLE_PRESS); }
public boolean isPressRelease() { return is(KeyPreset.PressType.PRESS_RELEASE); }
}
@@ -63,24 +63,27 @@ public class KeyPreset {
setDown(isDown);
}
private static final int SHORT_PRESS_TICKS = 5;
public void setDown(boolean down) {
if (down && !isDown)
if (down && !isDown) { // just pressed
pressTime = 0;
onAction(PressType.PRESS, PressType.PRESS_RELEASE);
if (!down && isDown) {
if (pressTime <= 5)
}
if (!down && isDown) { // just released
if (pressTime <= SHORT_PRESS_TICKS) {
onAction(PressType.SINGLE_PRESS);
onAction(PressType.RELEASE, PressType.PRESS_RELEASE);
}
onAction(PressType.RELEASE);
pressTime = 0;
}
if (isDown || down) //to fire in both press & release
onAction(PressType.HOLD);
if (isDown)
if (down) { // while held
pressTime++;
onAction(PressType.HOLD);
}
this.isDown = down;
}