![](/img/trans.png)
[英]How do I make the pyautogui.click() keep trying until the image show?
[英]Pyautogui : Autoclicker with Image recognition How do I make a function I made only run if an image is recognised?
我是 python 的新手,我知道我的代碼真的很亂。 我需要幫助,我希望下面的 function 僅在我設置的圖像被識別時運行mc_ok_button.png
但這有點令人困惑,因為我希望它加入我已經制作的循環。 如果我將代碼放在循環中,它不會運行它下面的函數的 rest 嗎?
我的圖像識別function:
import pyautogui as pg
import pydirectinput as pd
import time
ax,ay = pg.locateCenterOnScreen('mc_ok_button.png',confidence=.6)
def function_when_restart():
print(ax,ay)
pd.click(ax,ay)
print('Waiting to return back to the server...')
time.sleep(8)
pd.moveTo(892,531)
print('finding server...')
pd.click()
print('connecting to the server...')
function_when_restart()
然后我希望function_when_restart()
function 僅在mc_ok_button.png
圖像被識別並在function_when_restart()
運行時停止project()
和fix_tool()
時運行,然后繼續返回make project()
和fix_tool()
:
from time import monotonic
from time import monotonic, sleep
start = monotonic()
while monotonic() - start < (60) : #Run for exactly 1 minute
# I want the image recognition to always run and if the image pops up I want
project()
sleep(5)
fix_tool()
下面可以幫忙嗎?
while True:
image = pyautogui.locateOnScreen('image.png')
if image != None:
project()
sleep(5)
fix_tool()
else:
pass
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.