我的AHK图像检测没有满足我的要求

时间:2018-07-31 03:09:58

标签: autohotkey

所以我的代码当前由

组成
Loop
{
    CoordMode, Pixel, Window
    ImageSearch, FoundX, FoundY, 0, 0, 3440, 1440, C:\Users\MY_NAME\Pictures\PICTURE_TO_BE_FOUND.PNG
}
Until ErrorLevel = 0
If ErrorLevel
{
    Loop
    {
        Send, {Space}
        Sleep, 3000
    }
}
Else
{
    MsgBox, 48, Detection, Icon found, 2
    IfMsgBox, Timeout
    {
        Send, {Space}
        Sleep, 5000
    }
}

由于某种原因,我每隔3000毫秒按一下Space的第一个循环在无法检测到图片时什么也没做。是因为ImageSearch处于循环中吗?因为它一直在搜索并且想在继续之前找到它?如果是这种情况,我如何使它不断寻找图像,同时每3秒按一下空格键,然后在找到Else时转到FromBody

1 个答案:

答案 0 :(得分:1)

因此,我将您的问题读为:“每三秒钟按一下空格键,然后找到它,然后转到Else,如何使它不断寻找图像?”

这是我推荐的:

CoordMode, Pixel, Window ; only needs to be set once per routine (until Return is found)
Loop
{
    ImageSearch, FoundX, FoundY, 0, 0, 3440, 1440, C:\Users\MY_NAME\Pictures\PICTURE_TO_BE_FOUND.PNG
    If ErrorLevel  ; not found the picture
    {
        Send, {Space}
        Sleep, 3000
    }
}
Until ErrorLevel = 0
MsgBox, 48, Detection, Icon found, 2