2020-10-15 01:26:31 +00:00
|
|
|
from enum import Enum
|
2020-10-17 08:06:49 +00:00
|
|
|
from threading import Thread
|
2020-11-19 13:19:27 +00:00
|
|
|
from typing import Dict, Callable, Optional
|
2020-10-15 01:26:31 +00:00
|
|
|
|
2020-06-25 18:43:53 +00:00
|
|
|
import keyboard
|
2020-11-19 13:19:27 +00:00
|
|
|
from playsound import playsound
|
2020-06-25 18:43:53 +00:00
|
|
|
|
|
|
|
from fishy.helper import helper
|
|
|
|
|
2020-10-15 01:26:31 +00:00
|
|
|
|
|
|
|
class Key(Enum):
|
2020-10-17 22:04:25 +00:00
|
|
|
F9 = "f9"
|
2020-10-17 19:45:57 +00:00
|
|
|
F10 = "f10"
|
2020-10-15 01:26:31 +00:00
|
|
|
F8 = "f8"
|
|
|
|
F7 = "f7"
|
2020-10-17 22:04:25 +00:00
|
|
|
UP = "up"
|
2020-10-15 01:26:31 +00:00
|
|
|
DOWN = "down"
|
|
|
|
LEFT = "left"
|
|
|
|
RIGHT = "right"
|
2020-06-25 18:43:53 +00:00
|
|
|
|
|
|
|
|
2020-11-19 13:19:27 +00:00
|
|
|
_hotkeys: Dict[Key, Optional[Callable]] = {}
|
2020-06-25 18:43:53 +00:00
|
|
|
|
|
|
|
|
2020-11-19 13:19:27 +00:00
|
|
|
def _get_callback(k):
|
|
|
|
def callback():
|
|
|
|
if not _hotkeys[k]:
|
|
|
|
return
|
|
|
|
|
|
|
|
playsound(helper.manifest_file("beep.wav"), False)
|
|
|
|
Thread(target=_hotkeys[k]).start()
|
|
|
|
return callback
|
2020-06-25 18:43:53 +00:00
|
|
|
|
|
|
|
|
2020-10-15 01:26:31 +00:00
|
|
|
def initalize():
|
|
|
|
for k in Key:
|
2020-11-19 13:19:27 +00:00
|
|
|
_hotkeys[k] = None
|
|
|
|
keyboard.add_hotkey(k.value, _get_callback(k))
|
2020-06-25 18:43:53 +00:00
|
|
|
|
|
|
|
|
2020-11-19 13:19:27 +00:00
|
|
|
def set_hotkey(key: Key, func: Optional[Callable]):
|
2020-10-15 01:26:31 +00:00
|
|
|
_hotkeys[key] = func
|
|
|
|
|
|
|
|
|
|
|
|
def free_key(k: Key):
|
2020-11-19 13:19:27 +00:00
|
|
|
set_hotkey(k, None)
|