From e5e8e8948a11fdfe30e72c06aa92bea0e7dd55c3 Mon Sep 17 00:00:00 2001 From: bigguy345 Date: Fri, 19 Dec 2025 12:57:15 +0200 Subject: [PATCH] Improved pressTime calculation logic --- .../noppes/npcs/client/key/KeyPreset.java | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/main/java/noppes/npcs/client/key/KeyPreset.java b/src/main/java/noppes/npcs/client/key/KeyPreset.java index bc9dc720c..cbc7cfb86 100644 --- a/src/main/java/noppes/npcs/client/key/KeyPreset.java +++ b/src/main/java/noppes/npcs/client/key/KeyPreset.java @@ -23,7 +23,7 @@ public class KeyPreset { public boolean shouldConflict = true; public Consumer task; - public int pressTime; + private long pressStartMs = 0; public boolean isDown; @@ -63,29 +63,30 @@ public class KeyPreset { setDown(isDown); } - private static final int SHORT_PRESS_TICKS = 5; + private static final long SHORT_PRESS_MS = 250L; public void setDown(boolean down) { - if (down && !isDown) { // just pressed - pressTime = 0; + if (down && !isDown) { // just pressed + pressStartMs = System.currentTimeMillis(); onAction(PressType.PRESS, PressType.PRESS_RELEASE); } - - if (!down && isDown) { // just released - if (pressTime <= SHORT_PRESS_TICKS) { + + if (!down && isDown) { // just released + if (getPressTime() <= SHORT_PRESS_MS) onAction(PressType.SINGLE_PRESS); - } - onAction(PressType.RELEASE); - pressTime = 0; + onAction(PressType.RELEASE, PressType.PRESS_RELEASE); + pressStartMs = 0; } - if (down) { // while held - pressTime++; + if (down) // while held onAction(PressType.HOLD); - } this.isDown = down; } + + public long getPressTime() { + return pressStartMs > 0 ? (System.currentTimeMillis() - pressStartMs) : 0L; + } public KeyPreset onAction(PressType... pressTypes) { if (task != null) {