|
2 | 2 | import keyboard |
3 | 3 | import time |
4 | 4 |
|
5 | | -clicking = False |
6 | 5 |
|
| 6 | +def run_auto_clicker(delay: float = 0.01) -> None: |
| 7 | + """ |
| 8 | + Runs an auto clicker that can be controlled with keyboard hotkeys. |
7 | 9 |
|
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 |
12 | 16 |
|
| 17 | + def start_clicking(): |
| 18 | + nonlocal clicking |
| 19 | + clicking = True |
| 20 | + print("✅ Auto clicker started") |
13 | 21 |
|
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") |
18 | 33 |
|
| 34 | + try: |
| 35 | + while True: |
| 36 | + if clicking: |
| 37 | + pyautogui.click() |
| 38 | + time.sleep(delay) |
19 | 39 |
|
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 |
22 | 43 |
|
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.") |
26 | 46 |
|
27 | | -while True: |
28 | | - if clicking: |
29 | | - pyautogui.click() |
30 | | - time.sleep(0.001) |
31 | 47 |
|
32 | | - if keyboard.is_pressed("q"): |
33 | | - print("Exiting program") |
34 | | - break |
| 48 | +if __name__ == "__main__": |
| 49 | + run_auto_clicker() |
0 commit comments