summaryrefslogtreecommitdiffstats
path: root/Scripts/keybind_event_machine.py
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2023-05-22 03:59:45 -0700
committeryum <yum.food.vr@gmail.com>2023-05-22 04:04:09 -0700
commit8fafea9d026b2b65599456e70d3f5aa61ef073d1 (patch)
treee0a759534c0042797e07ae8b18e2841c64c303c9 /Scripts/keybind_event_machine.py
parentb2626a798768066e9611a8ec9c103b003a6debb8 (diff)
Add keyboard togglev0.11.4
Users can now configure a keybind to start/stop/dismiss the STT when in desktop mode. The default keybind is ctrl+x, since by default VRC doesn't use 'x' for anything.
Diffstat (limited to 'Scripts/keybind_event_machine.py')
-rw-r--r--Scripts/keybind_event_machine.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Scripts/keybind_event_machine.py b/Scripts/keybind_event_machine.py
new file mode 100644
index 0000000..3ce6794
--- /dev/null
+++ b/Scripts/keybind_event_machine.py
@@ -0,0 +1,21 @@
+import keyboard
+import time
+
+class KeybindEventMachine:
+ def __init__(self, keybind: str):
+ self.keybind = keybind
+ self.events = []
+ keyboard.add_hotkey(keybind, self.onPress)
+
+ def onPress(self) -> None:
+ self.events.append(time.time())
+
+ # Returns the timestamp when the keybind was pressed, or 0 if no keypresses
+ # are queued.
+ def getNextPressTime(self) -> int:
+ if len(self.events) == 0:
+ return 0
+ ret = self.events[0]
+ self.events = self.events[1:]
+ return ret
+