2

我一直在研究这个脚本,它点击屏幕上某种颜色的像素的任何位置,但我遇到了一个问题,当我循环它时它会截取屏幕截图,但在 30 秒循环中只有大约 12 个应该是程序以 600 的速度非常快速地单击像素。我迷路了

xx = 0
while xx <= 600:
    with mss.mss() as sct:
        region = {'top': 0, 'left': 0, 'width': 1920, 'height': 1080}
        imgg = sct.grab(region)
        img1 = mss.tools.to_png(imgg.rgb,imgg.size,output="C:/Users/yaahy/Desktop/scrnshotoutput/imageforgamehack"+str(xx)+".png")
        imgname = "C:/Users/yaahy/Desktop/scrnshotoutput/imageforgamehack"+str(xx)+".png"
    pxls = find_yellow_pixels(imgname)
    pyautogui.click(pxls[0],pxls[1])
    time.sleep(.05)
    xx = xx + 1
4

1 回答 1

1

首先,您应该重写以不MSS每次迭代都实例化一个新类,并删除睡眠:

import mss

with mss.mss() as sct:
    region = {'top': 0, 'left': 0, 'width': 1920, 'height': 1080}

    for xx in range(600):
        imgname = "C:/Users/yaahy/Desktop/scrnshotoutput/imageforgamehack" + str(xx) + ".png"
        imgg = sct.grab(region)
        img1 = mss.tools.to_png(imgg.rgb, imgg.size, output=imgname)
        # pxls = find_yellow_pixels(imgname)
        # pyautogui.click(pxls[0],pxls[1])

然后,正如评论者所建议的那样,您应该解释您想要实现的目标,也许您可​​以摆脱 PNG 创建并直接使用原始数据。

于 2019-02-24T17:25:03.703 回答