这是我正在使用的代码,我希望12秒后指针回到759、718并点击继续.
import time
import threading
import random
from pynput.mouse import Controller, Button
from pynput.keyboard import Listener, KeyCode
TOGGLE_KEY = KeyCode(char="1")
clicking = False
mouse = Controller()
#a=random.randint(176, 718)
#b=random.randint(732, 1215)
def clicker():
while True:
if clicking:
mouse.click(Button.right, 1)
for a in range(0, 10):
a=random.randint(732, 1215)
for b in range(0, 10):
b=random.randint(176, 500)
mouse.position=(a, b)
time.sleep(0.001)
def toggle_event(key):
if key == TOGGLE_KEY:
mouse.position = (759, 718)
global clicking
clicking = not clicking
click_threat = threading.Thread(target=clicker)
click_threat.start()
with Listener(on_press=toggle_event) as listener:
listener.join()
我try 了不同的方法来添加"if"的时间,但没有成功 我还try 了另一个time.sleep,但整个代码认为应该等待12秒才能执行,并且不会每0.001秒执行一次点击.