from ast import For
import time
import threading
from pynput.mouse import Button, Controller
from pynput.keyboard import Listener, KeyCode
from colorama import Fore
import os

# Made by stampe. @2022
# Declare global variables

delay = 0.001 # change this to 0.04 for ~30 cps & 0.001 for ~65 cps
button = Button.left
start_stop_key = KeyCode(char='s')
exit_key = KeyCode(char='e')
clickAmount = 0
start = time.time()
end = time.time()

def clear(): 
    command = 'cls'  
    if os.name != 'nt': 
    	command = 'clear'
    os.system(command)
    return 0

# Hjälp i början

print(Fore.MAGENTA + '[i]' + Fore.RESET + ' stampe´s AutoClicker Version' + Fore.LIGHTYELLOW_EX +  ' 1.0' + Fore.RESET)
print(Fore.YELLOW + '-------------------------------------------------------' + Fore.RESET)
print(Fore.LIGHTGREEN_EX + '[i]' + Fore.RESET +  ' Click {} to start and to pause while it´s running, {} to terminate proccess'.format(start_stop_key, exit_key))	
print(Fore.CYAN + '[i]' + Fore.RESET +  ' A clicker which clicks your mouse for you' + Fore.RESET)
print(Fore.LIGHTRED_EX + '[i]' + Fore.RESET + ' The average clicking speed is about ' + Fore.GREEN + '65' + Fore.RESET +  ' clicks per second')
print(Fore.LIGHTYELLOW_EX + '-------------------------------------------------------' + Fore.RESET)
# Statistik i slutet

def onclick(event): 
    global clickAmount
    clickAmount += 1


# Mouse controller

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)

# Main program

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()
            print(Fore.CYAN + '[i]' + Fore.RESET +  ' Clicker paused\n')
        else:
            click_thread.start_clicking()
            print(Fore.BLUE + '[i]' + Fore.RESET +  ' Clicker started\n')
    elif key == exit_key:
        click_thread.exit()
        listener.stop()
        print(Fore.RED + '[i]' + Fore.RESET +  ' Clicker terminated\n')
        clear()
        time.sleep(1)
        print(Fore.RED + '[!]' + Fore.RESET + ' Stopped and terminated process\n')
        print(Fore.LIGHTGREEN_EX + '[i]'+ Fore.RESET + ' Clicked {} times'.format(clickAmount) + '\n')
        print(Fore.LIGHTGREEN_EX + '[i]' + Fore.RESET + ' Executed in {} seconds'.format(end - start))

with Listener(on_press=on_press) as listener:
    listener.join()

from ast import For
import time
import threading
from pynput.mouse import Button, Controller
from pynput.keyboard import Listener, KeyCode
from colorama import Fore
import os

# Made by stampe. @2022
# Declare global variables

delay = 0.001 # change this to 0.04 for ~30 cps & 0.001 for ~65 cps
button = Button.left
start_stop_key = KeyCode(char='s')
exit_key = KeyCode(char='e')
clickAmount = 0
start = time.time()
end = time.time()

def clear(): 
    command = 'cls'  
    if os.name != 'nt': 
    	command = 'clear'
    os.system(command)
    return 0

# Hjälp i början

print(Fore.MAGENTA + '[i]' + Fore.RESET + ' stampe´s AutoClicker Version' + Fore.LIGHTYELLOW_EX +  ' 1.0' + Fore.RESET)
print(Fore.YELLOW + '-------------------------------------------------------' + Fore.RESET)
print(Fore.LIGHTGREEN_EX + '[i]' + Fore.RESET +  ' Click {} to start and to pause while it´s running, {} to terminate proccess'.format(start_stop_key, exit_key))	
print(Fore.CYAN + '[i]' + Fore.RESET +  ' A clicker which clicks your mouse for you' + Fore.RESET)
print(Fore.LIGHTRED_EX + '[i]' + Fore.RESET + ' The average clicking speed is about ' + Fore.GREEN + '65' + Fore.RESET +  ' clicks per second')
print(Fore.LIGHTYELLOW_EX + '-------------------------------------------------------' + Fore.RESET)
# Statistik i slutet

def onclick(event): 
    global clickAmount
    clickAmount += 1


# Mouse controller

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)

# Main program

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()
            print(Fore.CYAN + '[i]' + Fore.RESET +  ' Clicker paused\n')
        else:
            click_thread.start_clicking()
            print(Fore.BLUE + '[i]' + Fore.RESET +  ' Clicker started\n')
    elif key == exit_key:
        click_thread.exit()
        listener.stop()
        print(Fore.RED + '[i]' + Fore.RESET +  ' Clicker terminated\n')
        clear()
        time.sleep(1)
        print(Fore.RED + '[!]' + Fore.RESET + ' Stopped and terminated process\n')
        print(Fore.LIGHTGREEN_EX + '[i]'+ Fore.RESET + ' Clicked {} times'.format(clickAmount) + '\n')
        print(Fore.LIGHTGREEN_EX + '[i]' + Fore.RESET + ' Executed in {} seconds'.format(end - start))

with Listener(on_press=on_press) as listener:
    listener.join()

# Made by stampe. @2022 # Declare global variables # change this to 0.04 for ~30 cps & 0.001 for ~65 cps # Hjälp i början # Statistik i slutet # Mouse controller # Main program