Download Super Mouse Auto Clicker 4

  -  

This is a script that allows you to lớn cliông chồng your mouse repeatedly with a small delay. It works on Windows, Mac và Linux và can be controlled with user-defined keys.

Bạn đang xem: Download super mouse auto clicker 4


What is this?

This project uses the cross-platkhung module pynput khổng lồ control the mouse và monitor the keyboard at the same time to create a simple tự động hóa clicker.

PIP

If you haven"t used or cài đặt pip before, look at my tutorial on how to thiết đặt python"s pip to thiết lập pip.

Installing Pynput

We will be using the pynput module to listen to lớn mouse events. To install this module exeđáng yêu pip install pynput in cmd. Watch the output khổng lồ make sure no errors have occurred; it will tell you when the module has been successfully installed.

*

To double-check that it was installed successfully, open up IDLE và execute the commvà import pynput; no errors should occur.

*
.

Writing the Code

First, we need lớn import time and threading. Then import Button and Controller from pynput.mouse so we can control the mouse và import Listener và KeyCode from pynput.keyboard so we can watch for keyboard events khổng lồ start and stop the auto clicker.


import timeimport threadingfrom pynput.mouse import Button, Controllerfrom pynput.keyboard import Listener, KeyCode
Next create four variables as shown below. "delay" will be the delay between each button click. "button" will be the button to lớn clichồng, this can be either "Button.left", "Button.right" or even "Button.middle". "start_stop_key" is the key you want khổng lồ use khổng lồ start & stop the tự động hóa clicker. I have mix it lớn the key "s" to make it nice & simple, you can use any key here. Finally, the "exit_key" is the key to close the program set it like before, but make sure it is a different key.


delay = 0.001button = Button.leftstart_stop_key = KeyCode(char='s')exit_key = KeyCode(char='e')
Now create a class that extends threading.Thread that will allow us khổng lồ control the mouse clicks. Pass they delay and button khổng lồ this and have two flags that determine whether it is running or if the whole program is stopping.


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
Now we need to create the method that is run when the thread starts. We need to lớn keep looping while the program_running is true và then create another loop inside that checks if the running is phối khổng lồ true. If we are inside both loops, cliông xã the set button and then sleep for the mix delay.

Xem thêm: Tổng Quan Về Các Thiết Bị Ngoại Vi Là Gì ? Thiết Bị Ngoại Vi


def run(self): while self.program_running: while self.running: mouse.click(self.button) time.sleep(self.delay) time.sleep(0.1)
Now we want lớn create an instance of the mouse controller, create a ClickMouse thread and start it khổng lồ get inkhổng lồ the loop in the run method.


Now create a method called on_press that takes a key as an argument & setup the keyboard listener.


Now modify the on_press method. If the key pressed is the same as the start_stop_key, stop clicking if the running flag is mix khổng lồ true in the thread otherwise start it. If the key pressed is the exit key, Call the exit method in the thread & stop the listener. The new method will look lượt thích this:


def on_press(key): if key == start_stop_key: if click_thread.running: click_thread.stop_clicking() else: click_thread.start_clicking() elif key == exit_key: click_thread.exit() listener.stop()
This script can be saved as a .pyw to lớn run in the background. It can easily be still closed using the phối exit key even when no dialog is shown.

Using the Script

To use this script set the variables at the top to what you want.

delay: They delay between each mouse cliông chồng (in seconds)button: The mouse button khổng lồ click; Button.left | Button.middle | Button.rightstart_stop_key: They key to lớn start and stop clicking. Make sure this is either from the Key class or phối using a KeyCode as shown.exit_key: The key lớn stop the program. Make sure this is either from the Key class or mix using a KeyCode as shown.

Then run the script and use the start/stop key when wanted. Press the mix exit key lớn exit.

Final Code


import timeimport threadingfrom pynput.mouse import Button, Controllerfrom pynput.keyboard import Listener, KeyCodedelay = 0.001button = Button.leftstart_stop_key = KeyCode(char='s')exit_key = KeyCode(char='e')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) time.sleep(self.delay) time.sleep(0.1)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 == exit_key: click_thread.exit() listener.stop()with Listener(on_press=on_press) as listener: listener.join()

Common Issues và Questions

ModuleNotFoundError/ImportError: No module named "pynput"

Did you install pynput? This error will not occur if you installed it properly. If you have sầu multiple versions of Pynhỏ bé, make sure you are installing pynput on the same version as what you are running the script with.

I got a SyntaxError

Syntax errors are caused by you và there is nothing I can offer khổng lồ fix it apart from telling you to read the error. They always say where the error is in the output using a ^. Generally, people that get this issue have sầu incorrect indentation, brackets in the wrong place or something spelt wrong. You can read about SyntaxError on Python"s docs here.

"python" is not recognized as an internal or external command

Pykhông lớn hasn"t been installed or it hasn"t been installed properly. Go to /blog/post/how-to-setup-pythons-pip/ and follow the tutorial. Just before you enter the scripts folder into the path variable, remove the "scripts" part at the end. You will also want khổng lồ add another path with "scripts" to have pip.

Xem thêm: Game Lam Toc Cho Winx Club Hair Salon Trò Chơi Trực Tuyến, Lam Toc Cho Winx Game


About

Owner of PyTutorials & creator of auto-py-to-exe. I enjoy making quick tutorials for people new to particular topics in Pybé & tools that help fix small things.