我用 p子打上了天线,但有一个问题:需要太多时间进行屏幕(0.5秒)。 工作需要不到0.1秒。 我对马科斯说一米,因此,我认为屏幕显示比窗口要慢得多。
守则:
from pynput.keyboard import Listener, KeyCode
from pynput.mouse import Controller as MouseController, Button
from PIL import ImageGrab
import time
mouse = MouseController()
pixel_coords = [(590, 490), (492, 490), (678, 490), (766, 490)]
running = True
def click(x, y):
mouse.position = (x, y)
mouse.click(Button.left)
def play():
global running
while running:
print("Hey")
x = time.time()
screen = ImageGrab.grab()
for coord in pixel_coords:
value = screen.getpixel((coord[0], coord[1]))
if value in [(0, 0, 0, 255), (15, 20, 19, 255), (13, 32, 41, 255), (0, 161, 201, 255)]:
click(coord[0], coord[1])
print(f"Time taken: {round(time.time() - x, 4)}")
def on_press(key):
global running
if key == KeyCode(char="q"):
running = False
print("Stopped")
quit()
with Listener(on_press=on_press) as listener:
play()
listener.join()
我尝试了诸如Pyautogui和PIL等不同单元,但很缓慢。