import time import random import winsound from pynput import keyboard, mouse from start import get_start import threading import pyautogui from collect import Collect pyautogui.FAILSAFE = True pyautogui.PAUSE = 0.02 SOURCE = (490, 400) collect = Collect() def listener_keyword(): def on_press(key): global collect, SOURCE try: if key.char == "1": SOURCE = pyautogui.position() # 得到当前鼠标位置 print(pyautogui.position()) winsound.Beep(800, 200) elif key.char == "2": collect = Collect(pyautogui.position()) print(pyautogui.position()) winsound.Beep(800, 200) except AttributeError: pass with keyboard.Listener(on_press=on_press) as listener: listener.join() threading.Thread(target=listener_keyword, daemon=True).start() def rep(collect: Collect): for x, y in collect.get_all_target(): # 鼠标移动到SOURCE pyautogui.moveTo(SOURCE[0], SOURCE[1], random.random() / 5) time.sleep(random.random() / 30) # 右键 pyautogui.rightClick() time.sleep(random.random() / 30) # 放到 x, y pyautogui.moveTo(x, y, random.random() / 5) time.sleep(random.random() / 30) # 左键 pyautogui.leftClick() while True: time.sleep(0.1) if get_start() == False: continue rep(collect) collect() collect()