If ErrorLevel1 from PixelSearch not working after adding GUI Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Archandrion
Posts: 31
Joined: 26 May 2018, 22:23

If ErrorLevel1 from PixelSearch not working after adding GUI

27 May 2018, 22:28

For some reason PixelSearch below is not working after adding the GUI even when used on a black PNG file with no white pixels.

Code: Select all

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

Code: Select all

      
        ;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
        }
Archandrion
Posts: 31
Joined: 26 May 2018, 22:23

Re: If ErrorLevel1 from PixelSearch not working after adding GUI

29 May 2018, 11:41

Updated the question above with simpler code and more precise title as still unable to figure out why adding GUI breaks the PixelSearch function. I've tried other colors besides white as well but no luck.
Archandrion
Posts: 31
Joined: 26 May 2018, 22:23

Re: If ErrorLevel1 from PixelSearch not working after adding GUI

30 May 2018, 15:56

swagfag wrote:what coordmode are u using
Entered 'CoordMode, ToolTip, Screen' into the code as the coordinates were originally obtained using DefineBox() at https://autohotkey.com/board/topic/7169 ... ined-area/ which seems to use absolute screen coordinates but still not getting the correct response.

Code: Select all

CoordMode, ToolTip, Screen
;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, 0x000000, 3, Fast RGB
                  if ErrorLevel {
                     MsgBox Not Found
                  } else {
                     MsgBox %SomeText%
                  }


        Gui, Destroy ; Destroy the GUI
        Return
        }
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: If ErrorLevel1 from PixelSearch not working after adding GUI

30 May 2018, 17:58

DefineBox() doesnt appear to set CoordMode anywhere at all, so its using Relative/Window, and CoordMode, Tooltip, ... affects, well, ToolTips only.
Archandrion
Posts: 31
Joined: 26 May 2018, 22:23

Re: If ErrorLevel1 from PixelSearch not working after adding GUI  Topic is solved

31 May 2018, 00:11

swagfag wrote:DefineBox() doesnt appear to set CoordMode anywhere at all, so its using Relative/Window, and CoordMode, Tooltip, ... affects, well, ToolTips only.
I replaced that line with CoordMode, Pixel, Screen as shown below and now it works. Thanks for pointing that out.

Code: Select all

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 +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
                  {
                      
                      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
        }

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, Google [Bot], Rohwedder and 386 guests