-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto_macro.py
40 lines (34 loc) · 1.04 KB
/
auto_macro.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
import time
from pynput.keyboard import Controller, Listener, Key
# Starting number
counter = 1708
# Keyboard controller
keyboard = Controller()
# Flag to control the macro
running = False
def start_typing():
global running, counter
running = True
while running:
# Type the current counter value and press Enter
keyboard.type(str(counter))
keyboard.press(Key.enter)
keyboard.release(Key.enter)
counter += 1
time.sleep(2) # Wait 2 seconds before typing the next number
def on_press(key):
global running
try:
if key.char == 's': # Start typing when 's' is pressed
if not running:
print("Starting typing...")
start_typing()
elif key.char == 'q': # Stop typing when 'q' is pressed
running = False
print("Stopped typing.")
except AttributeError:
pass
# Listener for keyboard events
with Listener(on_press=on_press) as listener:
print("Press 's' to start and 'q' to stop.")
listener.join()