fishyboteso/fishy/engine/fullautofisher/controls.py

51 lines
1.3 KiB
Python
Raw Normal View History

import logging
2021-05-01 09:34:38 +00:00
from pynput.keyboard import Key
2021-04-18 07:22:57 +00:00
from fishy.helper import hotkey
2022-02-02 23:59:10 +00:00
# todo: unused code remove it
2021-05-01 09:34:38 +00:00
def get_controls(controls: 'Controls'):
controls = [
("MODE_SELECT", {
2021-05-01 09:34:38 +00:00
Key.DOWN: (lambda: controls.select_mode("TEST1"), "test mode"),
}),
2021-05-01 09:34:38 +00:00
("TEST1", {})
]
return controls
class Controls:
def __init__(self, controls, first=0):
self.current_menu = first - 1
self.controls = controls
def initialize(self):
self.select_mode(self.controls[0][0])
def log_help(self):
help_str = f"\nCONTROLS: {self.controls[self.current_menu][0]}"
for key, meta in self.controls[self.current_menu][1].items():
func, name = meta
if func:
hotkey.set_hotkey(key, func)
help_str += f"\n{key.value}: {name}"
logging.info(help_str)
def select_mode(self, mode):
self.current_menu = 0
for i, control in enumerate(self.controls):
if mode == control[0]:
self.current_menu = i
self.log_help()
def unassign_keys(self):
keys = []
for c in self.controls:
for k in c[1].keys():
if k not in keys:
hotkey.free_key(k)