autohotkey

Hotkey to restart autohotkey script?


Say I have an autohotkey script C:\path\to\my\script running. Is there a way to define a hotkey that re-starts it?


Solution

  • In order to prevent duplicate instances, I normally do not re-launch a script but use the build-in function Reload. I launch this with Ctrl+Win+Alt+R and use Ctrl+Win+Alt+E to edit the main AHK script.

    ^#!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