0
votes

New to AHK scripting, just picked up how to use ImageSearch, but now I would like to improve the quality of life of the script by creating a status. For e.g when the script is running, I would like to have a label text to allow me to know the script is running when it is trying to find the image, and vice versa to know if the script is not running. Tried to change label text when the while loop is running and when its not running but doesn't seem to be working. Any help is appreciated as I am new to this. Thanks!

        Gui,2:Add,Button,x10 y10 w200 h40 gFind_Image ,Start Image Search
        Gui,2:Add,Button,x10 w200 h40 gGui_1,Load / Reload image
        Gui,2:Add, Button,x10 w200 h40 gStop_Music, Stop Music
        Gui,2:Add, Text, x10, Press Numpad 1 to stop `n  
        Gui,2:Add, Text, vStartStop x10,  Stop
        Gui,2:Add, Text,x20
        Gui,2:Show, x1000 y300, Image search
        return



    2GuiClose:
        ExitApp


; StartStop:
; GuiControlGet, Text
;     if (Stop:=0) 
;     {
;         GuiControl,, Text, Stop
;         Gosub, Start
;     }
;     else if (Stop:=1)
;     {
;         GuiControl,, Text, Start
;         Gosub, Stop
;     }
; return

MyTimer: 
if (A_sec <> 10)
return
Settimer, MyTimer, off 


Find_Image:

    Stop:= 0
    While(Stop=0)
        {


            ;ImageSearch, OutputVarX, OutputVarY, X1, Y1, X2, Y2, ImageFile
            ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, wizet.png

                if(ErrorLevel = 1)
                {
                    ;
                    Traytip,, Image not found, 1
                    Sleep, 2000

                }
                else if (ErrorLevel = 0)
                {
                    ;play sound as image is found 
                    musicPlay:= 0             
                    ;SoundPlay, %W%, wait]
                    Stop:=1
                }    
        }

    return
1

1 Answers

0
votes

It seems the code you provided is a fragment of script, that said. I believe you tried using the GuiControl. That is the correct command to use in this case.

You have a set a control gui id using vStartStop, so to modiy the text you have to do something like this.

GuiControl,, StartStop, My new text here...

I believe you'll want to insert a statement like GuiControl,, StartStop, search running... inside your while loop at the beginning, and one outside after your while loop: GuiControl,, StartStop, search stopped....