修改后自动重新加载AutoHotkey脚本 [英] Automatically reload AutoHotkey script when modified
本文介绍了修改后自动重新加载AutoHotkey脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在测试AutoHotkey脚本时,有时我忘记进行更改后重新加载脚本.这导致我不小心测试了脚本的旧的,过时的版本.
When testing AutoHotkey scripts, I sometimes forget to reload my scripts after making changes. This leads to me accidentally testing old, outdated versions of my scripts.
我希望让脚本在被修改后自动重新加载,而不是手动重新加载脚本.
Instead of manually reloading the script, I would like to have scripts automatically reload if they have been modified.
无论何时修改.ahk
文件,如何使AutoHotkey重新加载当前脚本?
How can I make AutoHotkey reload the current script any time a .ahk
file is modified?
推荐答案
Somewhere near start of script, in the auto-execute section
#SingleInstance force
FileGetTime ScriptStartModTime, %A_ScriptFullPath%
SetTimer CheckScriptUpdate, 100, 0x7FFFFFFF ; 100 ms, highest priority
脚本中的任意位置(通常在底部):
Anywhere in the script (usually somewhere at the bottom):
CheckScriptUpdate() {
global ScriptStartModTime
FileGetTime curModTime, %A_ScriptFullPath%
If (curModTime <> ScriptStartModTime) {
SetTimer CheckScriptUpdate, Off
Loop
{
reload
Sleep 300 ; ms
MsgBox 0x2, %A_ScriptName%, Reload failed. ; 0x2 = Abort/Retry/Ignore
IfMsgBox Abort
ExitApp
IfMsgBox Ignore
break
} ; loops reload on "Retry"
}
}
这篇关于修改后自动重新加载AutoHotkey脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文