fix: "debounce" keypresses
This commit is contained in:
parent
f03ba40760
commit
49b057658e
1 changed files with 17 additions and 10 deletions
|
@ -17,25 +17,32 @@ public class QuickModule extends Module {
|
||||||
private class ToggleHook {
|
private class ToggleHook {
|
||||||
private final KeyBinding key;
|
private final KeyBinding key;
|
||||||
private final Module mod;
|
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) {
|
protected ToggleHook(KeyBinding key, Module mod) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.mod = mod;
|
this.mod = mod;
|
||||||
|
this.debounce = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
private void onInput() {
|
||||||
public void onKeyPress(InputEvent.KeyInputEvent event) {
|
if (this.debounce) {
|
||||||
|
if (!this.key.isDown()) {
|
||||||
|
this.debounce = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if (this.key.isDown()) {
|
if (this.key.isDown()) {
|
||||||
this.mod.toggle(); // TODO debounce this
|
this.mod.toggle();
|
||||||
|
this.debounce = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onKeyPress(InputEvent.MouseInputEvent event) {
|
public void onKeyPress(InputEvent.KeyInputEvent event) { this.onInput(); }
|
||||||
if (this.key.isDown()) {
|
@SubscribeEvent
|
||||||
this.mod.toggle(); // TODO debounce this
|
public void onKeyPress(InputEvent.MouseInputEvent event) { this.onInput(); }
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final KeyBinding keybind;
|
public final KeyBinding keybind;
|
||||||
|
|
Loading…
Reference in a new issue