簡體   English   中英

通過將Sikuli與Java一起不斷搜索圖像

[英]Constantly search for an image by using Sikuli with Java

我正在使用Sikuli API制作圖像檢測機器人,我想知道是否有人知道如何使它不斷掃描圖像,然后單擊它? 目前它將掃描然后單擊,但是我希望它不斷掃描。

怎么樣:

int mil = MaxMillis;
boolean flagIsFound = false;

while (mil > 0 && flagIsFound != true)
        {
            Thread.sleep(1000);
            mil -= 1000;
            System.out.println("wait for the image a sec");
            if (screen.exists(image) != null)
            {
                // found
                flagIsFound = true;
            }
        }
        if(flagIsFound == false)
        {
            throw new SikuliException(image + " not found for " + MaxMillis + " milliseconds");
        }

您是否需要對其進行掃描,直到出現它,然后單擊該圖像,否則圖像會再次出現,並且您需要它在每次彈出時都單擊該圖像嗎? 無論哪種方式,我都認為您的解決方案很簡單-

要進行掃描,直到其彈出,然后單擊一次,然后不再進行掃描-

while not exists(yourImage):
    wait(1) #can also use sleep()
click(yourImage)

為了繼續掃描並一次又一次地單擊,請將其包裝在另一個“ while”語句中,例如-

while True: 
    while not exists(yourImage):
        wait(1)
    click(yourImage)
    if (someConditionIsMet):
        break

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM