-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeyboard-macro.py
More file actions
66 lines (56 loc) · 2.14 KB
/
keyboard-macro.py
File metadata and controls
66 lines (56 loc) · 2.14 KB
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
65
66
#!/usr/bin/env python3
#Created by PepeBigotes
import os
from keyboard import *
RECORD_HOTKEY = 'ctrl+alt+q'
PLAY_HOTKEY = 'ctrl+alt+p'
STOP_HOTKEY = 'ctrl+alt+space'
os.system('cls' if os.name=='nt' else 'clear')
print("""\
┬┌─┌─┐┬ ┬┌┐ ┌─┐┌─┐┬─┐┌┬┐ ┌┬┐┌─┐┌─┐┬─┐┌─┐
├┴┐├┤ └┬┘├┴┐│ │├─┤├┬┘ ││───│││├─┤│ ├┬┘│ │
┴ ┴└─┘ ┴ └─┘└─┘┴ ┴┴└──┴┘ ┴ ┴┴ ┴└─┘┴└─└─┘
""")
print(f" 'Record' hotkey: {RECORD_HOTKEY.upper()}")
print(f" 'Play' hotkey: {PLAY_HOTKEY.upper()}")
print(f" 'Stop' hotkey: {STOP_HOTKEY.upper()}")
print( "------------------------------------------")
running = True
def stop_all(): # Stops the script, but as it runs on a separate thread it does not fully exit
global running
running = False
unhook_all_hotkeys()
unhook_all()
print("keyboard-macro Stopped,\nPress CTRL+C to exit the script")
exit()
def exit_all(): # Stops and exits the scripts fully
global running
running = False
unhook_all_hotkeys()
unhook_all()
print("Exiting keyboard-macro...\n")
exit()
add_hotkey(STOP_HOTKEY, stop_all)
try:
print(f"Press {RECORD_HOTKEY.upper()} to begin recording")
print(f"Then press {RECORD_HOTKEY.upper()} again to stop recording")
if not running: exit_all()
wait(RECORD_HOTKEY)
if not running: exit_all()
print(f"Recording macro...")
macro = record(until=RECORD_HOTKEY)
if not running: exit_all()
print(f"Macro recorded! You can now play by pressing {PLAY_HOTKEY.upper()}")
print(f"When you are done, stop the script by pressing {STOP_HOTKEY.upper()}")
while True:
wait(PLAY_HOTKEY)
if not running: exit_all()
print("Playing macro...")
play(macro)
if not running: exit_all()
print("Macro finished playing!")
print(f"You can play it again by pressing {PLAY_HOTKEY.upper()}")
print(f"Or stop the script by pressing {STOP_HOTKEY.upper()}")
except KeyboardInterrupt:
print("\nKeyboardInterrupt")
exit_all()