1
我想暂停包含While
循环和一些函数的AutoIt脚本。但我只能关闭HotKeySet()
上的脚本。我该如何暂停?暂停按热键循环
该脚本检查屏幕的一部分(x,y坐标在配置文件中设置)的更改,并在播放警告声音后拍摄屏幕截图。按暂停按钮时,它不会停止While
循环。但关闭程序的作品。这里是我的代码:
Global $Paused, $counter = 0
HotKeySet("{1}", "TogglePause")
HotKeySet("{2}", "Terminate")
HotKeySet("{3}", "ShowMessage")
Init()
Start()
While 1
$counter +=1
ToolTip('Script is "Running"',0,0, $counter, 1)
Sleep(700)
Switch TrayGetMsg()
Case $resume
Start()
DisableAlert()
Case $exit
ExitLoop
Exit
EndSwitch
WEnd
//some of the functions
Func Start()
$ready = 0
$count = 0
$lastScreenshotNum = 0
TrayItemSetState($resume, $TRAY_DISABLE)
TraySetIcon("on.ico")
TakeScreenshot()
AdlibRegister(TakeScreenshot,2000)
EndFunc
Func Stop()
AdlibUnRegister(TakeScreenshot)
TraySetIcon("off.ico")
TrayItemSetState($resume, $TRAY_ENABLE)
EndFunc
Func TogglePause()
Stop()
$Paused = NOT $Paused
While $Paused
sleep(100)
ToolTip('Script is "Paused"',0,0, $counter, 1)
WEnd
ToolTip("")
EndFunc
Func Terminate()
Exit 0
EndFunc
Func ShowMessage()
MsgBox(4096,"","This is a message.")
EndFunc
Func EnableAlert()
SendMail()
Alert()
AdlibRegister(Alert,5000)
EndFunc
Func DisableAlert()
AdlibUnRegister(Alert)
EndFunc
Func Alert()
SoundPlay("alert.mp3")
EndFunc
你TogglePause功能确实暂停截图,但是你错过了回切换。如果不是$暂停,则添加,然后在TogglePause结束时开始()。有用。 – Milos