Skip to content

Commit 13110fe

Browse files
authored
PR #70: Refractored Auto Clicker
Refactor auto clicker for improved structure and configurability Merge pull request #70 from Tithi234/patch-2
2 parents 303f68a + 152f53e commit 13110fe

1 file changed

Lines changed: 36 additions & 21 deletions

File tree

Auto-Clicker/auto_clicker.py

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,48 @@
22
import keyboard
33
import time
44

5-
clicking = False
65

6+
def run_auto_clicker(delay: float = 0.01) -> None:
7+
"""
8+
Runs an auto clicker that can be controlled with keyboard hotkeys.
79
8-
def start_clicking():
9-
global clicking
10-
clicking = True
11-
print("Auto clicker started")
10+
Controls:
11+
- Press 'S' to start clicking
12+
- Press 'E' to stop clicking
13+
- Press 'Q' to quit
14+
"""
15+
clicking = False
1216

17+
def start_clicking():
18+
nonlocal clicking
19+
clicking = True
20+
print("✅ Auto clicker started")
1321

14-
def stop_clicking():
15-
global clicking
16-
clicking = False
17-
print("Auto clicker stopped")
22+
def stop_clicking():
23+
nonlocal clicking
24+
clicking = False
25+
print("⏹ Auto clicker stopped")
26+
27+
keyboard.add_hotkey("s", start_clicking)
28+
keyboard.add_hotkey("e", stop_clicking)
29+
30+
print("Press 'S' to start clicking")
31+
print("Press 'E' to stop clicking")
32+
print("Press 'Q' to quit")
1833

34+
try:
35+
while True:
36+
if clicking:
37+
pyautogui.click()
38+
time.sleep(delay)
1939

20-
keyboard.add_hotkey("s", start_clicking)
21-
keyboard.add_hotkey("e", stop_clicking)
40+
if keyboard.is_pressed("q"):
41+
print("👋 Exiting program")
42+
break
2243

23-
print("Press 'S' to start clicking")
24-
print("Press 'E' to stop clicking")
25-
print("Press 'Q' to quit")
44+
except KeyboardInterrupt:
45+
print("\nProgram interrupted by user.")
2646

27-
while True:
28-
if clicking:
29-
pyautogui.click()
30-
time.sleep(0.001)
3147

32-
if keyboard.is_pressed("q"):
33-
print("Exiting program")
34-
break
48+
if __name__ == "__main__":
49+
run_auto_clicker()

0 commit comments

Comments
 (0)