0
votes

For some reason PixelSearch below is not working after adding the GUI even when used on a black PNG file with no white pixels. Needed it to work as part of a loop.

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

However it does work correctly in the code without GUI below. Is there a way to add GUI without making the loop not work?

    ;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
well probably the GUI is blocking the view? or the backbround window gets darker because not in focus anymore?phil294

1 Answers

0
votes

Was advised on the AutoHotkey forums that the CoordMode could be what was affecting the PixelSearch. Found that the code worked by adding CoordMode, Pixel, Screen on the first line as shown below.

    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
    }