【问题标题】:Constantly search for an image by using Sikuli with Java使用 Sikuli 和 Java 不断搜索图像
【发布时间】:2013-12-24 20:50:20
【问题描述】:

我正在使用 Sikuli API 制作一个图像检测机器人,我想知道是否有人知道如何让它不断扫描图像,然后点击它?目前它会扫描然后点击,但我希望它不断扫描。

【问题讨论】:

    标签: java image sikuli


    【解决方案1】:

    怎么样:

    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");
            }
    

    【讨论】:

      【解决方案2】:

      你需要它扫描直到它出现然后点击图像,还是图像会重复出现,你需要它每次弹出图像时点击它?不管怎样,我认为你的解决方案很简单--

      扫描直到弹出,然后点击一次,就不再扫描了--

      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
      

      【讨论】:

        猜你喜欢
        • 2014-05-10
        • 2014-06-16
        • 1970-01-01
        • 2017-05-30
        • 2010-12-11
        • 2016-04-10
        • 2016-11-06
        • 1970-01-01
        • 2021-12-23
        相关资源
        最近更新 更多