编程和 AHK 新手,需要帮助构建 AHK GUI,其中至少有三个按钮可以运行 3 个不同的脚本,并且按钮的颜色可以是绿色,以显示脚本正在运行,如果我再次单击以使其停止,则按钮颜色变为红色。我有一些东西,但我想给按钮添加一种颜色,以了解脚本是否正在运行。
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
答案1
尝试这个
#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