我正在尝试运行以下代码,但始终出现错误。
import time
import threading
from pynput.mouse import Button, Controller
from pynput.keyboard import Listener, KeyCode
from random import randint
mouse = Controller()
numbers = [0.08, 0.05, 0.012, 0.07, 0.06, 0.012, 0.05, 0.014, 0.02]
delay = numbers[randint(0,8)]
button = Button.left
start_stop_key = KeyCode(char='F')
exit_key = KeyCode(char='e')
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)
time.sleep(0.1)
click_thread = ClickMouse(delay, button)
click_thread.start()
def on_press(key):
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()
with Listener(on_press=on_press) as listener:
listener.join()
错误:
file "C:\Users\jpbas\OneDrive\Desktop\autoclicker.py", line 47, in <module>
click_thread = ClickMouse(delay, button)
AssertionError: group argument must be None for now
>>>
我该如何解决?
答案 0 :(得分:0)
请查阅this文档,以获取有关group
参数的解释以及为什么必须使用None
。
根据该文档,您收到的错误似乎来自
super(ClickMouse, self).__init__()
行,因为这是您初始化threading.Thread
实例的地方。
尝试将关键字参数group=None
放在此处(即使这是该参数的默认值)。
另一方面,运行代码不会给我任何错误。在环境中还有其他可能会影响这一点的东西吗?