Created
May 16, 2023 20:45
-
-
Save dantsec/401807b996a746ad58258d44e92ba3f4 to your computer and use it in GitHub Desktop.
Auto clicker made in Python!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Installing Packages: | |
pip install threading argparse pynput | |
Run example: | |
python auto_clicker.py -d 1.0 -b right -s . -f , | |
""" | |
import threading | |
import argparse | |
from time import sleep | |
from pynput.mouse import Button, Controller | |
from pynput.keyboard import Listener, KeyCode | |
class ClickMouse(threading.Thread): | |
def __init__(self, delay, button): | |
super(ClickMouse, self).__init__() | |
self.delay = delay | |
self.button = button | |
self.running = False | |
self.program_running = True | |
def start_clicking(self): | |
self.running = True | |
def stop_clicking(self): | |
self.running = False | |
def exit(self): | |
self.stop_clicking() | |
self.program_running = False | |
def run(self): | |
while self.program_running: | |
while self.running: | |
mouse.click(self.button) | |
sleep(self.delay) | |
sleep(0.1) | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser(description="Click to Conquer!") | |
parser.add_argument('-d', '--delay', dest='delay', type=float, default=1.0, help='Time delay to Click (default: 1.0)') | |
parser.add_argument('-b', '--button-key', dest='button', type=str, default='left', help='[Left / Right] Click (default: left)') | |
parser.add_argument('-s', '--start', dest='start', type=str, default='a', help='Key to start / resume script (default: a)') | |
parser.add_argument('-f', '--finish', dest='finish', type=str, default='b', help='Key to finish script (dafault: b)') | |
args = parser.parse_args() | |
delay = args.delay | |
button = Button.right if args.button == 'right' else Button.left | |
start_stop_key = KeyCode(char=args.start) | |
stop_key = KeyCode(char=args.finish) | |
mouse = Controller() | |
click_thread = ClickMouse(delay, button) | |
click_thread.start() | |
def on_press(key): | |
if key == start_stop_key: | |
if click_thread.running: | |
click_thread.stop_clicking() | |
else: | |
click_thread.start_clicking() | |
elif key == stop_key: | |
click_thread.exit() | |
listener.stop() | |
with Listener(on_press=on_press) as listener: | |
listener.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment