blob: 3ce67947479d539c3a781c72c1524e65116e5acf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
|