[英]How to I make my python program take screenshots faster?
我一直在研究這個腳本,它點擊屏幕上某種顏色的像素,但我遇到了一個問題,當我循環它時,它會截取屏幕截圖,但在 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
首先,你應該重寫,不要在每次迭代中實例化一個新的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 創建並直接使用原始數據。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.