首页 > 解决方案 > 为什么延迟不会改变我的自动点击器的点击速度?

问题描述

您好 Stack Overflow 用户,我想知道如何修复我的Python Auto Clicker。这是Python 3.9.7,我正在使用Visual Studio Code中的Visual Studio Code程序,当我更改delay变量时,它仍然以相同的速度单击。我正在使用pynput导入来检查是否按下了键并获取鼠标,pynput.keyboardpynput.mouse还使用from pynput import mouse. 无论如何,他们是否让我自己的等待脚本有点像time.sleep(float)无论如何让我们进入重点。这是代码:

###################
## Python Script Made by: Ryans World
## Python Script Based off of: PyTutorials on YouTube
## Python Version: 3.9.7
## Recommended Versions: 3.10 or 3.9.7
###################
    
# Imports
    
import threading
import time
from pynput import mouse
from pynput.mouse import Button, Controller
from pynput.keyboard import Key, Listener

# Variables

delay = 0.01
button = Button.left

# Functions

class ClickMouse(threading.Thread):
    def __init__(self, delay, button):
        super().__init__()
        self.delay = delay
        self.button = button
        self.running = False
        self.program_running = True
    
    # Run the script;returns True
    def start_clicking(self):
        self.running = True
    
    # Stop the script;returns False
    def stop_clicking(self):
        self.running = False
    
    # Exit the program;breaks the script
    def exit(self):
        self.stop_clicking()
        self.program_running = False
    
    # Runs the AutoClicking
    def run(self):
        while self.program_running:
            while self.running:
                mouse.click(self.button)
                time.sleep(self.delay)

# Thread & Mouse

mouse = Controller()
click_thread = ClickMouse(delay, button)
click_thread.start()

# Checks if USER pressed key to run program
def on_press(key):
    if key == Key.alt_l:
        if click_thread.running:
            click_thread.stop_clicking()
        else:
            click_thread.start_clicking()
    elif key == Key.esc:
        click_thread.exit()
        listener.stop() # Shuts down program completely

# Joins the Program with the 'on_press' function
with Listener(on_press=on_press) as listener:
    listener.join()

标签: pythonpynput

解决方案


推荐阅读