python - 为什么延迟不会改变我的自动点击器的点击速度?
问题描述
您好 Stack Overflow 用户,我想知道如何修复我的Python Auto Clicker。这是Python 3.9.7,我正在使用Visual Studio Code中的Visual Studio Code程序,当我更改delay
变量时,它仍然以相同的速度单击。我正在使用pynput导入来检查是否按下了键并获取鼠标,pynput.keyboard
我pynput.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()
解决方案
推荐阅读
- ssl - Letsencrypt + nginx + 自动更新 + 基础设施即代码?
- sympy - 创建只包含真实值的 IndexedBase
- vba - 将代码从 excel 2010 复制到 excel 2013 并且无法正常工作
- c# - 进程因堆栈溢出而终止
- javascript - 使用 javascript 的内部音频记录
- android - onclick imageview 时,Fragment Activity 崩溃
- powershell - Set-SPSiteAdministration cmdlet - 所有者用户别名
- path - 如何列出文件夹并返回特定文件类型的所有文件名?
- c# - 使用 ASP.NET MVC 和 IIS 10 浏览网站时出现错误 404
- json - JSON API - DirectException("请求正文不是 unjson()-able: %s" % body)