Skip to content

Instantly share code, notes, and snippets.

@starch0
Last active April 2, 2024 12:53
Show Gist options
  • Save starch0/6af9d4461928fa700f5c81c0bca80f09 to your computer and use it in GitHub Desktop.
Save starch0/6af9d4461928fa700f5c81c0bca80f09 to your computer and use it in GitHub Desktop.
auto clicker
from pynput.mouse import Button, Controller
from pynput.keyboard import Key, Listener
import threading
import time
mouse = Controller()
clicking = False
def on_press(key):
global clicking
if key.char == 'k':
clicking = True
threading.Thread(target=auto_click).start()
def on_release(key):
global clicking
if key == Key.esc:
clicking = False
return False
def auto_click():
while clicking:
mouse.click(Button.left, 1)
time.sleep(0.1)
def start_listener():
with Listener(on_press=on_press, on_release=on_release) as listener:
listener.join()
if __name__ == "__main__":
start_listener()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment