fix: "debounce" keypresses

This commit is contained in:
əlemi 2023-01-31 22:25:17 +01:00
parent f03ba40760
commit 49b057658e
No known key found for this signature in database
GPG key ID: BBCBFE5D7244634E

View file

@ -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) {
private void onInput() {
if (this.debounce) {
if (!this.key.isDown()) {
this.debounce = false;
}
} else {
if (this.key.isDown()) {
this.mod.toggle(); // TODO debounce this
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;