-
Notifications
You must be signed in to change notification settings - Fork 0
/
play.py
64 lines (51 loc) · 1.95 KB
/
play.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import keyboard
import mouse
from time import time
import logs
import listeners
import util
import threading
def play_macro():
if (len(listeners.macro) < 2):
logs.play_macro_empty()
return
logs.playing_started()
def worker():
listeners.playing = True
macro_copy = listeners.macro.copy()
started_time = time()
macro_started_time = macro_copy[0]["time"]
macro_copy.pop(0)
while True:
if (len(macro_copy) == 0):
break
current_time = time() - started_time
macro_current_event_time = macro_copy[0]["time"] - macro_started_time
if (current_time >= macro_current_event_time):
name = macro_copy[0]["name"]
event = macro_copy[0]["event"]
match name:
case "keyboard":
keyboard.send(event["scan_code"], event["event_type"] == "down", event["event_type"] == "up")
logs.key(event, False)
case "mouse-button":
if (event["event_type"] == "down"):
mouse.press(event["button"])
else:
mouse.release(event["button"])
logs.mouse_click(event, False)
case "mouse-move":
mouse.move(event["x"], event["y"])
logs.mouse_move(event, False)
case "mouse-wheel":
mouse.wheel(event["delta"])
logs.mouse_wheel(event, False)
macro_copy.pop(0)
util.release_macro_keys()
util.release_mouse_buttons()
logs.playing_stopped()
listeners.playing = False
if listeners.repeat: worker()
return
thread = threading.Thread(target=worker)
thread.start()