1

New to programming and AHK need help to build AHK GUI with at least three buttons to run 3 different scripts, and to show color in the button could be green to show that the script is running and if I click again to make it stop so becomes red. I have something but I would like to add like a color to the buttons to know that the script is not running or it is.

Gui, Add, Button, w200 h50 gTest1 , Run test1.AHK Script
Gui, Add, Button, w200 h50 gTest2 , Run test2.AHK Script
Gui, Show,, Print Options
Return

Test1:
Run combine_scripts.ahk
Return

Test2:
Run fast.ahk
Return
0

Try this

#NoEnv
#SingleInstance Force
SetWorkingDir %A_ScriptDir%

DetectHiddenWindows On
SetTitleMatchMode 2

If WinExist("Script1.ahk - AutoHotkey v1 ahk_class AutoHotkey")
    S1 := true
else
    S1 := false
If WinExist("Script2.ahk - AutoHotkey v1 ahk_class AutoHotkey")
    S2 := true
else
    S2 := false
If WinExist("Script3.ahk - AutoHotkey v1 ahk_class AutoHotkey")
    S3 := true
else
    S3 := false

Gui -Caption +AlwaysOnTop 
Gui, Font, s12, Verdana 

If (S1)
{
    Gui, Add, Button, x5 w70 h20 gRunStopScript1, Stop
    Gui, Add, Progress, vA1 x80 ym w300 h20 cGreen, 100
}
else
{
    Gui, Add, Button, x5 w70 h20 gRunStopScript1, Run
    Gui, Add, Progress, vA1 x80 ym w300 h20 cRed, 100
}
Gui, Add, Text, xp+20 vB1 w200 cWhite +BackgroundTrans, Script1.ahk

If (S2)
{
    Gui, Add, Button, x5 w70 h20 gRunStopScript2, Stop
    Gui, Add, Progress, vA2 x80 y37 w300 h20 cGreen, 100
}
else
{
    Gui, Add, Button, x5 w70 h20 gRunStopScript2, Run
    Gui, Add, Progress, vA2 x80 y37 w300 h20 cRed, 100
}
Gui, Add, Text, xp+20 vB2 w200 cWhite +BackgroundTrans, Script2.ahk

If (S3)
{
    Gui, Add, Button, x5 w70 h20 gRunStopScript3, Stop
    Gui, Add, Progress, vA3 x80 y67 w300 h20 cGreen, 100
}
else
{
    Gui, Add, Button, x5 w70 h20 gRunStopScript3, Run
    Gui, Add, Progress, vA3 x80 y67 w300 h20 cRed, 100
}
Gui, Add, Text, xp+20 vB3 w200 cWhite +BackgroundTrans, Script3.ahk

SetTimer, ReloadScript, 1000 

Gui, Show, x10 y10, Run/Stop a Script
Return

RunStopScript1:
If (S1)
    WinClose, Script1.ahk - AutoHotkey v1 ahk_class AutoHotkey
else
    Run, Script1.ahk
Reload
Return

RunStopScript2:
If (S2)
    WinClose, Script2.ahk - AutoHotkey v1 ahk_class AutoHotkey
else
    Run, Script2.ahk
Reload
Return

RunStopScript3:
If (S3)
    WinClose, Script3.ahk - AutoHotkey v1 ahk_class AutoHotkey
else
    Run, Script3.ahk
Reload
Return

ReloadScript:
If (S1)
{
    If !WinExist("Script1.ahk - AutoHotkey v1 ahk_class AutoHotkey")
        Reload
}
else
{
    If WinExist("Script1.ahk - AutoHotkey v1 ahk_class AutoHotkey")
        Reload
}
If (S2)
{
    If !WinExist("Script2.ahk - AutoHotkey v1 ahk_class AutoHotkey")
        Reload
}
else
{
    If WinExist("Script2.ahk - AutoHotkey v1 ahk_class AutoHotkey")
        Reload
}
If (S3)
{
    If !WinExist("Script3.ahk - AutoHotkey v1 ahk_class AutoHotkey")
        Reload
}
else
{
    If WinExist("Script3.ahk - AutoHotkey v1 ahk_class AutoHotkey")
        Reload
}
Return
| improve this answer | |
  • Ty friend I will try it. – Rafael C Apr 5 at 3:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.