SingleInstance force ; 确保脚本只有一个实例在运行
input:= InputBox("设置定时关机, 请输入关机倒计时时间(分钟):", "时间设置")
if input.result="Cancel"{
ExitApp
return
}
else
Minutes :=input.value
; 检查输入是否合法
If (!IsNumber(Minutes) || Minutes <= 0) {
Result := MsgBox("你要立刻关机吗?",, "YesNo")
if Result = "Yes"{
;MsgBox "You pressed Yes."
Shutdown 1 ; 1 表示关机,更多选项可以参考 AHK 文档
ExitApp ; 关闭GUI后停止脚本的执行
return
}
else{
;MsgBox "You pressed No."
ExitApp ; 关闭GUI后停止脚本的执行
return
}
}
; 弹出确认框
Result := MsgBox(Format("关机确认, 确定要在{1}分钟后关机吗?",Minutes),, "YesNo")
if Result = "No"{
ExitApp ; 关闭GUI后停止脚本的执行
return
}
; 开始倒计时
global time:=Minutes*60
global countdownGui := 0
global countdownText := ""
ShowCountdownGUI()
return
; 检查是否是数字
IsNumber(number) {
return RegExMatch(number, "^\d+$")
}
ShowCountdownGUI() {
global time
Mygui:=Gui()
MyGui.SetFont("s24","Font")
minu:=Floor(time/60)
sec:=time-minu*60
if minu<10
global CountdownText:=Mygui.Add("Text","x50 y30 w100 h30 ","0" . minu . ":0" . sec)
else
global CountdownText:=Mygui.Add("Text","x50 y30 w100 h30 ",minu . ":0" . sec)
MyGui.SetFont("s14","Font")
StopTimer:=Mygui.Add("Button","Default x50 y70 w100 h30","停止关机")
StopTimer.OnEvent("Click", ButtonStop) ; 当点击时, 调用 ButtonStop
MyGui.Title :="关机"
Mygui.show("w200 h150")
myGui.OnEvent("Close", ButtonStop)
setTimer CountDown, 1000
return
CountDown(){
global CountdownText
global time
time := time - 1
minu:=Floor(time/60)
sec:=time-minu*60
if minu<10
if sec<10
CountdownText.Text:="0" . minu . ":0" . sec
else
CountdownText.Text:="0" . minu . ":" . sec
else
if sec<10
CountdownText.Text:= minu . ":0" . sec
else
CountdownText.Text:= minu . ":" sec
if (time <= 0) {
shutdown 1
SetTimer , 0
ExitApp
Return
}
Return
}
ButtonStop(*){
;SetTimer , 0
;MsgBox "关机已停止!"
ExitApp
Return
}
}
|