添加GUI后,PixelSearch在AutoHotkey脚本中无法正常工作

时间:2018-05-29 16:15:49

标签: loops user-interface autohotkey break

出于某种原因,即使在没有白色像素的黑色PNG文件上使用,添加GUI后,下面的PixelSearch也无法正常工作。需要它作为循环的一部分工作。

    ;Pres P on keyboard to test
    p::SearchPixels()
    Esc::exitapp

    SearchPixels(){
    ;DefinRegion
    TLX = 1104
    TLY = 373
    BRX = 1422
    BRY = 452
    SomeText := "Found"
        Gui,+AlwaysOnTop
        Gui, Add, Text, cLime, %SomeText%
        Gui, Show, xCenter yCenter

              PixelSearch, FoundX, FoundY, TLX, TLY, BRX, BRY, 0xFFFFFF, 3, Fast RGB
              if ErrorLevel {
                 MsgBox Not Found
              } else {
                 MsgBox %SomeText%
              }


    Gui, Destroy ; Destroy the GUI
    Return
    }

然而,它在没有GUI的代码中可以正常工作。有没有办法添加GUI而不使循环不起作用?

    ;Pres P on keyboard to test
    p::SearchPixels()
    Esc::exitapp

    SearchPixels(){
    ;DefinRegion
    TLX = 1104
    TLY = 373
    BRX = 1422
    BRY = 452
    SomeText := "Found"


              PixelSearch, FoundX, FoundY, TLX, TLY, BRX, BRY, 0xFFFFFF, 3, Fast RGB
              if ErrorLevel {
                 MsgBox Not Found
              } else {
                 MsgBox %SomeText%
              }

    Return
    }

1 个答案:

答案 0 :(得分:0)

在AutoHotkey论坛上被告知CoordMode可能会影响PixelSearch。通过在第一行添加CoordMode,Pixel,Screen来发现代码的工作原理如下所示。

    CoordMode, Pixel, Screen
    ;Pres P on keyboard to test
    p::SearchPixels()

    `::exitapp
     ^1::Reload

    SearchPixels(){
    Global Var
    ;DefinRegion
    SomeText = Found
    ;Coordinates gotten from the DefineBox(TLX, TLY, BRX, BRY, BW, BH) function found in DefineBox.ahk not added here for brevity.
    ;Screen size of 1920x1080
    TLX = 650
    TLY = 905
    BRX = 1281
    BRY = 983
        Gui,+LastFound +AlwaysOnTop -Caption +Owner
        Gui,+HWND_G
        CustomColor = EEAA99  ; Can be any RGB color.
        Gui, Color, %CustomColor%
        Size := 12
        FontType := "Verdana"
        Gui, Font, s%Size%, %FontType%
        GUIWidth = 500
        GUIHeight = 50
        Gui, Add, Text, x0 y1 W%GUIWidth% H%GUIHeight% cLime +Center vVar, 0
        ; Make all pixels of this color transparent and make the text itself translucent (150): 
        WinSet, TransColor, %CustomColor% 150
        TLXn := TLX - 10
        TLYn := TLY - 10
        BelowSearchArea := TLYn + GUIHeight
        CenterX := ((BRX - TLXn) / 2) + TLXn - (GUIWidth / 2)
        Gui, Show, x%CenterX% y%BelowSearchArea% W%GUIWidth% H%GUIHeight%

              Loop
              {
                  ;small adjustment based on something on my screen that I'm not sure about.
                  PixelSearch, FoundX, FoundY, TLXn, TLYn, BRX, BRY, 0xFFFFFF, 1, Fast RGB
                  if ErrorLevel {
                     GuiControl,,Var, 0
                  } else {
                     GuiControl,,Var, 1
                  }
              }
    Gui, Destroy ; Destroy the GUI
    Return
    }