我正在尝试制作一个自动点击器,当我按下鼠标中的宏“x2”时开始点击并在我按下鼠标的宏“x1”时保持点击,问题是当我按下 x1 时代码的运行开始滞后,然后当我的鼠标按下某物时侦听器停止接收,直到我再次运行代码
from pynput import mouse
from pynput.keyboard import KeyCode, Listener, Controller
import pyautogui
import time
import threading
button = mouse.Button.left
mouseP = mouse.Controller()
keyP = Controller()
class ClickMouse(threading.Thread):
def __init__(self, button):
super(ClickMouse,self).__init__()
self.button = button
self.running = False
self.program_running = True
self.hold_running = False
def start_clicking(self):
self.running = True
def stop_clicking(self):
self.running = False
def start_hold_clicking(self):
self.hold_running = True
mouseP.press(button.left)
keyP.press(key.a)
def stop_hold_clicking(self):
self.hold_running = False
mouseP.release(button.left)
keyP.release(key.a)
def run(self):
while self.program_running:
while self.running:
pyautogui.click(button="left")
time.sleep(0.25)
click_thread = ClickMouse(button)
click_thread.start()
def on_click(x,y,button,pressed):
if button == button.x2 and pressed == False:
if click_thread.running:
click_thread.stop_clicking()
else:
click_thread.start_clicking()
if button == button.x1 and pressed == False:
if click_thread.hold_running:
print('yes')
click_thread.stop_hold_clicking()
else:
print('no')
click_thread.start_hold_clicking()
with mouse.Listener(on_click=on_click) as listener:
listener.join()
只有打印“no”出现,然后我不能再做任何事情了 如果有人告诉我出了什么问题,我将不胜感激