English 中文(简体)
是否能够更快地在马科斯上对甲型六氯环己烷的tile子进行筛查?
原标题:Is there a faster way to take screenshots on macOS for a Python piano tiles bot?
  • 时间:2023-05-20 02:52:17
  •  标签:

我用 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等不同单元,但很缓慢。

问题回答

暂无回答




相关问题
热门标签