Firstly, I use the following ahk-specific extensions in vscode:
- "AutoHotkey v2 Language Support(v1.9.2)" by thqby, and
- "vscode-autohotkey-debug(v1.11.0)" by zero-plusplus.
Secondly, I uninstalled AutoHotkey and re-installed a fresh version of v1.1 from the website. This gave me the following directory structure:
For v1, use Run & Debug from the vscode context menu (mouse right click)
This runs the interpreter specified in the Auto Hotkey2: Interpreter Path setting of thqby's extension. I’ve set this to C:\Program Files\AutoHotkey\AutoHotkeyU64.exe.
For v2, use Run & Debug from the vscode Run menu
By default this runs the interpreter specified in zero-plusplus' extension, ie: C:/Program Files/AutoHotkey/v2/AutoHotkey.exe. So, first making backups of both files, I renamed AutoHotkey64.exe as AutoHotkey.exe. Obviously this will need to be re-done each time there is a new release of v2!
Other notes:
- In all cases, file extensions are “.ahk”. Never any variant of this.
- If you accidentally run v1 the v2 way, or vice versa, vscode reports errors in the Panels (see code.visualstudio.com/docs/getstarted/userinterface). These errors make it obvious something’s gone wrong!
- To simply run the *.ahk file outside of vscode, double click it in file explorer. The fresh install above, provides a script launcher (configured through the new Dash utility). This checks the script for clues as to which version of ahk should be used to run it. But if you include #Requires (eg #Requires AutoHotkey v1.1, or #Requires AutoHotkey v2.0) as appropriate at the head of each script, then that’s best.