Code Monkey home page Code Monkey logo

autoclicker's Introduction

Prerequisites

  • Python 3.6 (For linux users can be most recent python version)

How to use it

There's 3 variables to modify:

BIND_KEY - The keyboard button name that going to enable/disable the auto clicker

CLICK_PER_SECONDS - How many times the button need to be pressed in a second.

BIND_MOUSE_BUTTON - What's the button the auto clicker is going to press. 1 - Left | 2 - Right | 3 - Middle

Windows users

cd /your/cloned/folder/directory
run_application.bat

Linux users

cd /your/cloned/folder/directory
chmod +x run_application.sh
./run_application

Python script

# The keyboard key that's enable/disable the auto clicker
BIND_KEY = 'F12'

# How many clicks will do in a second
CLICK_PER_SECONDS = 1

# What's the button that going to be pressed: 1 - Left | 2 - Right | 3 - Middle
BIND_MOUSE_BUTTON = 2

import logging
import os
import subprocess
import sys
import time
from threading import Thread

is_windows = sys.platform.startswith('win')

try:
    from pykeyboard import PyKeyboardEvent
    from pymouse import PyMouse
except ModuleNotFoundError:
    __install_dependencies = (lambda name:
                              subprocess.Popen(args=['python', '-m', 'pip', 'install', *name.split(' ')]).communicate())

    __install_dependencies('--upgrade pip')
    if is_windows:
        __install_dependencies('pywin32')
        abs_path = os.path.join(os.path.dirname(__file__), 'win32', 'pyHook-1.5.1-cp36-cp36m-win32.whl')
        __install_dependencies(abs_path)
    else:
        __install_dependencies('Xlib')

    __install_dependencies('PyUserInput')
finally:
    from pykeyboard import PyKeyboardEvent
    from pymouse import PyMouse


class AutoClicker(PyKeyboardEvent):
    def __init__(self):
        super(AutoClicker, self).__init__()
        self.mouse = PyMouse()

        self.keycode = None if is_windows else self.lookup_character_keycode(BIND_KEY)
        self.enable = False
        self.sleep = 1 / CLICK_PER_SECONDS

        self.logger = self.__create_logger()

    def run(self):
        self.logger.info('AutoClick: Started')
        super(AutoClicker, self).run()

    def tap(self, keycode, character, press):
        if press and (keycode == self.keycode or character == BIND_KEY):
            self.enable = not self.enable
            if self.enable:
                self.logger.info('AutoClick: Enabled')
                Thread(target=self.__click).start()
            else:
                self.logger.info('AutoClick: Disabled')

    def __click(self):
        while self.enable:
            x, y = self.mouse.position()
            self.mouse.click(x, y, button=BIND_MOUSE_BUTTON)
            if self.enable:
                time.sleep(self.sleep)

    @staticmethod
    def __create_logger():
        logger = logging.getLogger()
        logger.setLevel(logging.INFO)

        handler = logging.StreamHandler(sys.stdout)
        handler.setLevel(logging.INFO)
        formatter = logging.Formatter('%(asctime)s - %(message)s')
        handler.setFormatter(formatter)
        logger.addHandler(handler)
        return logger


AutoClicker().run()

autoclicker's People

Contributors

kafels avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.