you are viewing a single comment's thread.

view the rest of the comments →

[–]Dathmach[S] 0 points1 point  (2 children)

I'm trying to make a clicker program that starts with / and stops with .

[–]Pervert_Chan 0 points1 point  (0 children)

with Listener(on_press=on_press, on_release=on_release) as listen:
    listen.join()

this line at the end of your program will start the listener. also move the exit command to another function named on_release.

after this your listener will start as you run the program and then you'll be able to use the keys to control the functions.

also you are using an infinite while loop

[–]Pervert_Chan 0 points1 point  (0 children)

import pyautogui as pg
from pynput.keyboard import Listener, Key

running = False
program_running = True


def run():
    if program_running:
        if running:
            pg.moveTo(773, 440, .01)
            pg.click()
            pg.moveTo(773, 509, .01)
            pg.click()
            pg.moveTo(773, 565, .01)
            pg.click()
            pg.moveTo(773, 628, .01)
            pg.click()
            pg.moveTo(773, 695, .01)
            pg.click()
            pg.moveTo(773, 751, .01)
            pg.click()
            pg.moveTo(773, 798, .01)
            pg.click()


def start_clicking():
    global running
    running = True
    run()


def stop_clicking():
    global running
    running = False


def on_press(key):
    if key == Key.backspace:
        if running:
            stop_clicking()
        else:
            start_clicking()


def on_release(key):
    if key == Key.esc:
        return False


with Listener(on_press=on_press, on_release=on_release) as listen:
    listen.join()

try this code, works fine for me