修改时自动重新加载 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.
如何让 AutoHotkey 在 .ahk
文件被修改时重新加载当前脚本?
How can I make AutoHotkey reload the current script any time a .ahk
file is modified?
推荐答案
脚本开头的某处,在 自动执行部分
#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)
return
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屋!
查看全文