[英]Hotkey to restart autohotkey script?
Say I have an autohotkey script C:\\path\\to\\my\\script
running. 假设我有一个autohotkey脚本C:\\path\\to\\my\\script
运行。 Is there a way to define a hotkey that re-starts it? 有没有办法定义一个重新启动它的热键?
In order to prevent duplicate instances, I normally do not re-launch a script but use the build-in function Reload . 为了防止重复实例,我通常不会重新启动脚本,而是使用内置函数Reload 。 I launch this with Ctrl + Win + Alt + R and use Ctrl + Win + Alt + E to edit the main AHK script. 我使用Ctrl + Win + Alt + R启动它,然后使用Ctrl + Win + Alt + E编辑主AHK脚本。
^#!r::Reload
Actually, my script looks like this: 实际上,我的脚本看起来像这样:
^#!r::
Send, ^s ; To save a changed script
Sleep, 300 ; give it time to save the script
Reload
Return
^!#e::Edit
As a matter of fact, all the way at the top of my script I have this to give me a visual and audio indication that the script was restarted: 事实上,在我的脚本顶部,我有这个给我一个视觉和音频指示脚本重新启动:
#SingleInstance Force
#installKeybdHook
#Persistent
Menu, Tray, Icon , Shell32.dll, 25, 1
TrayTip, AutoHotKey, Started, 1
SoundBeep, 300, 150
Return
Make a hotkey that runs a script, which in this case is the same script and then exit. 创建一个运行脚本的热键,在这种情况下是相同的脚本,然后退出。
somehotkey::
Run, C:\path\to\my\script.ahk
ExitApp
return
I found this to be the safest option of them all, because it takes care that the correct script is reloaded when you have multiple scripts running simultaneously, which was a recurring issue for me. 我发现这是所有这些中最安全的选项,因为当你同时运行多个脚本时,需要注意重新加载正确的脚本,这对我来说是一个反复出现的问题。 The combination of the following also ensures that only one instance of a script will ever run at a time. 以下组合还可确保一次只运行一个脚本实例。 The ScriptFullPath variable includes the name of the script. ScriptFullPath变量包含脚本的名称。
#SingleInstance Force ;put this at the top of the script
^r::run, %A_ScriptFullPath%
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.