python - 尝试使用 python 制作自动点击器
问题描述
所以我尝试使用 python 制作一个自动点击器(我还是 python 新手),并且自动点击器本身可以工作。现在我正在尝试增加点击之间的延迟,并消除点击之间的延迟,但由于某种原因它不起作用。有谁知道为什么?
import time
import threading
from pynput.mouse import Button, Controller
from pynput.keyboard import Listener, KeyCode
global delay
delay = 0.005
button = Button.left
start_stop_key = KeyCode(char="n")
exit_key = KeyCode(char="e")
up_key = pynput.keyboard.Key[0]
down_key = pynput.keyboard.Key[0]
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)
mouse = Controller()
click_thread = ClickMouse(delay, button)
click_thread.start()
def on_press(key):
delay = 0.005
if key == start_stop_key:
if click_thread.running:
click_thread.stop_clicking()
else:
click_thread.start_clicking()
elif key == exit_key:
click_thread.exit()
listener.stop()
elif key == down_key:
delay += 0.005
elif key == up_key:
delay -= 0.005
with Listener(on_press=on_press) as listener:
listener.join()
解决方案
推荐阅读
- r-markdown - 无法使用 Rmarkdown 编织
- c++ - pthread FIFO调度不是严格确定的吗?
- javascript - pubnup 视频聊天在远程网络上不起作用
- javascript - 如何在javascript中检查对象的属性数组是否为空
- java - 我得到一个通用链表的空指针异常?
- codeigniter - 如何在 drop 函数中获取标题、开始和结束数据
- d3.js - D3JS 从数组数据中绘制折线图(数据未定义错误)
- c - 虽然在C中的一个变量中循环多个输入
- image - Imagewriter 只执行最后一次调用
- excel - 使用 vba 从 Sharepoint 文件夹和子文件夹中获取 excel 文件路径