【问题标题】:AHK PixelSearch LoopAHK PixelSearch 循环
【发布时间】:2022-01-10 23:45:09
【问题描述】:

我正在尝试让我的 AHK 脚本正常工作。 基本上我想找到一排颜色为 0x26FDFD (BGR) 的 x 像素。但是我不太了解 AHK 脚本语言,不足以考虑一种智能、干净且简单的方法来编写该循环,即将根据最后找到的坐标修改起点。

但是,到目前为止,这是我得到的:

    SysGet, VirtualWidth, 78
    SysGet, VirtualHeight, 79
    
    ;Farbe nach der gesucht wird:
    ColorVar := 0x26FDFD

    i:=0
    while i < 10
    {
        PixelSearch, FoundX, FoundY, 0, 0, VirtualWidth, VirtualHeight, %ColorVar%, 3, Fast
        if (ErrorLevel = 2)
        {
            MsgBox Could not conduct the search.
            return
        }
        else if (ErrorLevel = 1)
        {
            MsgBox Color could not be found on the screen.
            return
        }
        else
        {
            MouseMove, %FoundX%, %FoundY%
            MsgBox Found a Pixel at %FoundX%x%FoundY%.
            ;return
        }
        
        i++
    }

有点愚蠢和基本的问题,但不知何故我无法弄清楚。

【问题讨论】:

  • 也许您只想使用ImageSearch
  • 我试过了,但由于多种原因我无法让它稳定工作......所以我会用 Pixelsearch 试一试。

标签: autohotkey


【解决方案1】:

我只需要在每个循环结束时存储 X 和 Y 坐标,然后相应地设置新的起点。

代码如下:

i:=0
while i < 5
{
    PixelSearch, FoundX, FoundY, startX%A_Index%, startY%A_Index%, VirtualWidth, VirtualHeight, %ColorVar%, 3, Fast
    Switch ErrorLevel
    {
        Case 1:
            MsgBox Website ueberpruefen!
            return
        Case 2:
            MsgBox Makro ueberpruefen!
            return
        Default:            
            MouseMove, %FoundX%, %FoundY%
            ;MsgBox Found a Pixel at %FoundX%x%FoundY%.
            nextLoop := A_Index + 1
            startX%nextLoop% := FoundX + 1
            startY%nextLoop% := FoundY
    }
    
    i++
}
;msgbox % "found 5 matches!, first at: " startX2 "x" startY2
return

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-26
    • 1970-01-01
    • 2021-10-31
    • 1970-01-01
    • 1970-01-01
    • 2018-12-24
    相关资源
    最近更新 更多