diff options
author | alemidev <me@alemi.dev> | 2023-01-31 22:25:17 +0100 |
---|---|---|
committer | alemidev <me@alemi.dev> | 2023-01-31 22:25:17 +0100 |
commit | 49b057658e534dc358395e952114880c1129a9ae (patch) | |
tree | dcb2bddc061cc00c56752c314046e2cd4c81b58f /src/main | |
parent | f03ba40760258668c212d1da20527b7dfc95e2b0 (diff) |
fix: "debounce" keypresses
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/co/fantabos/bscv/module/QuickModule.java | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/main/java/co/fantabos/bscv/module/QuickModule.java b/src/main/java/co/fantabos/bscv/module/QuickModule.java index b6a0be0..470aa5e 100644 --- a/src/main/java/co/fantabos/bscv/module/QuickModule.java +++ b/src/main/java/co/fantabos/bscv/module/QuickModule.java @@ -17,25 +17,32 @@ public class QuickModule extends Module { private class ToggleHook { private final KeyBinding key; private final Module mod; + private boolean debounce; + // TODO all examples show isPressed() to get a debounced value + // but it seems to be missing? making my own debounce for now protected ToggleHook(KeyBinding key, Module mod) { this.key = key; this.mod = mod; + this.debounce = false; } - @SubscribeEvent - public void onKeyPress(InputEvent.KeyInputEvent event) { - if (this.key.isDown()) { - this.mod.toggle(); // TODO debounce this + private void onInput() { + if (this.debounce) { + if (!this.key.isDown()) { + this.debounce = false; + } + } else { + if (this.key.isDown()) { + this.mod.toggle(); + this.debounce = true; + } } } @SubscribeEvent - public void onKeyPress(InputEvent.MouseInputEvent event) { - if (this.key.isDown()) { - this.mod.toggle(); // TODO debounce this - - } - } + public void onKeyPress(InputEvent.KeyInputEvent event) { this.onInput(); } + @SubscribeEvent + public void onKeyPress(InputEvent.MouseInputEvent event) { this.onInput(); } } public final KeyBinding keybind; |