what i did today was make an auto clicker that can turn on and off with a button
import time
import threading
from pynput.mouse import Button, Controller
from pynput.keyboard import Listener, KeyCode
# Settings
CLICK_DELAY = 0.01 # seconds between clicks
START_STOP_KEY = KeyCode(char='s')
EXIT_KEY = KeyCode(char='e')
mouse = Controller()
clicking = False
def click_loop():
"""Click while 'clicking' is True."""
while True:
if clicking:
mouse.click(Button.left)
time.sleep(CLICK_DELAY)
else:
time.sleep(0.0001)
def on_press(key):
"""Handle key presses."""
global clicking
if key == START_STOP_KEY:
clicking = not clicking
print("Clicking:", clicking)
elif key == EXIT_KEY:
print("Exiting...")
return False # Stop listener
if __name__ == "__main__":
print("Press 's' to start/stop clicking, 'e' to exit.")
# Start click loop in background
threading.Thread(target=click_loop, daemon=True).start()
# Listen for keyboard events
with Listener(on_press=on_press) as listener:
listener.join()
Leave a Reply