mirror of
https://github.com/fishyboteso/fishyboteso.git
synced 2024-08-30 18:32:13 +00:00
created multiprocess solution for mouse click callback for recording
This commit is contained in:
parent
96db413f61
commit
babcdd262a
@ -6,8 +6,8 @@ from tkinter.filedialog import asksaveasfile
|
||||
|
||||
from fishy.engine.fullautofisher.engine import FullAuto, State
|
||||
|
||||
from fishy.helper import hotkey
|
||||
from fishy.helper.hotkey import Key
|
||||
from fishy.helper.hotkey_process import HotKey
|
||||
|
||||
|
||||
class Recorder:
|
||||
@ -35,7 +35,8 @@ class Recorder:
|
||||
def _start_recording(self):
|
||||
FullAuto.state = State.RECORDING
|
||||
logging.info("starting, press f8 to mark hole")
|
||||
hotkey.set_hotkey(Recorder.mark_hole_key, self._mark_hole)
|
||||
hk = HotKey()
|
||||
hk.start_process(self._mark_hole)
|
||||
|
||||
self.timeline = []
|
||||
|
||||
@ -52,7 +53,7 @@ class Recorder:
|
||||
else:
|
||||
logging.warning("Took too much time to record")
|
||||
|
||||
hotkey.free_key(Recorder.mark_hole_key)
|
||||
hk.stop()
|
||||
|
||||
def func():
|
||||
_file = None
|
||||
|
46
fishy/helper/hotkey_process.py
Normal file
46
fishy/helper/hotkey_process.py
Normal file
@ -0,0 +1,46 @@
|
||||
import time
|
||||
from threading import Thread
|
||||
|
||||
import mouse
|
||||
from multiprocessing import Process, Queue
|
||||
|
||||
|
||||
def event_triggered(queue, e):
|
||||
if not (type(e) == mouse.ButtonEvent and e.event_type == "up" and e.button == "left"):
|
||||
return
|
||||
|
||||
# call the parent function here
|
||||
queue.put("left click")
|
||||
|
||||
|
||||
def run(inq, outq):
|
||||
mouse.hook(lambda e: event_triggered(outq, e))
|
||||
|
||||
stop = False
|
||||
while not stop:
|
||||
time.sleep(1)
|
||||
if inq.get() == "stop":
|
||||
stop = True
|
||||
|
||||
|
||||
class HotKey:
|
||||
def __init__(self):
|
||||
self.inq = Queue()
|
||||
self.outq = Queue()
|
||||
|
||||
self.process = Process(target=run, args=(self.inq, self.outq))
|
||||
|
||||
def event_loop(self, func):
|
||||
while True:
|
||||
msg = self.outq.get()
|
||||
if msg == "left click":
|
||||
func()
|
||||
|
||||
def start_process(self, func):
|
||||
self.process.start()
|
||||
Thread(target=self.event_loop, args=(func,)).start()
|
||||
|
||||
def stop(self):
|
||||
self.inq.put("stop")
|
||||
self.process.join()
|
||||
print("hotkey process ended")
|
Loading…
Reference in New Issue
Block a user