Quick tutorial for setting up VSCode for AHK
Quick tutorial for setting up VSCode for AHK
I was asked for quick instructions on how to set up VSCode for AHK use, and it was suggested I post it here as it might benefit others. It's pretty easy, but it might not be clear if you're new to VSCode:
1. Download and run the Visual Studio Code installer.
2. Install an AHK extension: Open VSCode and select Extensions by either clicking the icon on the left bar (looks like four squares with one separated from the others) or by pressing Ctrl+Shift+X. Search for AutoHotkey and select your desired extension. You can also browse extensions at the VSCode Extension Marketplace. I currently use AutoHotkey Plus Plus after also using its predecessors that it was forked from.
3. (Optional) Set the default language for AHK so the AHK extension will work before even saving the file with a .ahk file extension (i.e., AHK syntax highlighting and everything else is applied to new windows that aren't saved yet): Go to the File menu, then Preferences, then Settings, or press Ctrl+,. With the Settings open, press Ctrl+F and search for "default language" and put in ahk.
Once you have set up one instance with your settings and extensions, it's easy to sync settings across multiple machines, which I find extremely useful as I have these and many other changes such as theme settings that are instantly applied to my other machines (virtual or otherwise) when I choose.
1. Download and run the Visual Studio Code installer.
2. Install an AHK extension: Open VSCode and select Extensions by either clicking the icon on the left bar (looks like four squares with one separated from the others) or by pressing Ctrl+Shift+X. Search for AutoHotkey and select your desired extension. You can also browse extensions at the VSCode Extension Marketplace. I currently use AutoHotkey Plus Plus after also using its predecessors that it was forked from.
3. (Optional) Set the default language for AHK so the AHK extension will work before even saving the file with a .ahk file extension (i.e., AHK syntax highlighting and everything else is applied to new windows that aren't saved yet): Go to the File menu, then Preferences, then Settings, or press Ctrl+,. With the Settings open, press Ctrl+F and search for "default language" and put in ahk.
Once you have set up one instance with your settings and extensions, it's easy to sync settings across multiple machines, which I find extremely useful as I have these and many other changes such as theme settings that are instantly applied to my other machines (virtual or otherwise) when I choose.
Re: Quick tutorial for setting up VSCode for AHK
If you're using v2, I would recommend AutoHotkey2 Language Support by thqby.
It is possible to use multiple language extensions, such as for v1 and v2. The current language is shown at the bottom-right of the screen. Clicking it brings up a menu to switch the language for the current file. This menu also includes an option "Configure File Association for '.ahk'" (or presumably whatever extension the current file has) to change the default language for files of that type.
It is possible to use multiple language extensions, such as for v1 and v2. The current language is shown at the bottom-right of the screen. Clicking it brings up a menu to switch the language for the current file. This menu also includes an option "Configure File Association for '.ahk'" (or presumably whatever extension the current file has) to change the default language for files of that type.
-
- Posts: 18
- Joined: 23 Jan 2014, 03:02
Re: Quick tutorial for setting up VSCode for AHK
It might be worth noting that if using thqby's AutoHotkey2 Language Support, I believe debugging requires it's own extension. I use vscode-autohotkey-debug. Whereas it looks like AutoHotkey Plus Plus can handle debugging on its own, but I could be mistaken since I haven't used it much.
Re: Quick tutorial for setting up VSCode for AHK
It's probably worth adding here how to set up VSCode to be the default editor for .ahk files. Use the Registry Editor to point to the VSCode executable path here:
Your VSCode executable may be located in AppData > Local > Programs instead of your Program Files folder.
Your VSCode executable may be located in AppData > Local > Programs instead of your Program Files folder.
Re: Quick tutorial for setting up VSCode for AHK
If you install AutoHotkey v2, it will ask you which editor to use the first time you attempt to edit a script. VS Code should be detected automatically, so you can select it from the list. This list can also be accessed from the Dash at any time, to change the default editor.
Re: Quick tutorial for setting up VSCode for AHK
That's a nice feature. Thanks for adding it.
Re: Quick tutorial for setting up VSCode for AHK
On Windows 10, the above didn't work for me when using the "Edit This Script" option in the right-click/context menu of the AHK tray icon. This, however, solved the problem.
www.autohotkey.com/board/topic/23889-how-to-edit-this-script-in-any-editor-other-than/?p=543108
For future-proofing, here's the text from the linked post:
www.autohotkey.com/board/topic/23889-how-to-edit-this-script-in-any-editor-other-than/?p=543108
For future-proofing, here's the text from the linked post:
I prefer Sublime Text, so I modified the .reg file as follows.Below is a .reg script that changes editor to use when picking an option "Edit this script" from tray icon menu.
Code: Select all
Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Applications\AutoHotkey.exe\shell\edit] [HKEY_CLASSES_ROOT\Applications\AutoHotkey.exe\shell\edit\command] @="\"c:\\Program Files (x86)\\Notepad++\\notepad++.exe\" \"%1\""
Code: Select all
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Applications\AutoHotkey.exe\shell\edit]
[HKEY_CLASSES_ROOT\Applications\AutoHotkey.exe\shell\edit\command]
@="\"C:\\Program Files\\Sublime Text\\sublime_text.exe\" \"%1\""
- Curdflappers
- Posts: 11
- Joined: 13 Nov 2020, 03:18
- Contact:
Re: Quick tutorial for setting up VSCode for AHK
Yep, AHK has basic debugging support, but if you need something fancy then vscode-autohotkey-debug is great. And we're working on v2 support now so that folks don't have to install multiple extensions just to write code in one language!OpalMonkey wrote: ↑24 Apr 2022, 08:07It might be worth noting that if using thqby's AutoHotkey2 Language Support, I believe debugging requires it's own extension. I use vscode-autohotkey-debug. Whereas it looks like AutoHotkey Plus Plus can handle debugging on its own, but I could be mistaken since I haven't used it much.
Re: Quick tutorial for setting up VSCode for AHK
Got a question regarding running scripts off VSCode. It seems that when I run another script VSCode command line exits the currently running v2 script. How do we run multiple?
Re: Quick tutorial for setting up VSCode for AHK
Do you mean you want to run multiple scripts from VSCode? It may depend on the plug-in, but in general, you shouldn’t be using VSCode as a launcher. Using an editor to launch code should be for checking a script while developing it, not to be used as your general approach for launching scripts.
Re: Quick tutorial for setting up VSCode for AHK
I like to use VScode to launch them because I keep editing and making improvements.
Other than double clicking the ahk file how else should we run them ?
Other than double clicking the ahk file how else should we run them ?
Re: Quick tutorial for setting up VSCode for AHK
That's the way I suggest. Not sure why you're looking for another way. You could also put a shortcut to them in the Windows Startup folder and other approaches that are used to launch apps when appropriate.
Re: Quick tutorial for setting up VSCode for AHK
Reviving.
How do we pass command line arguments in VSCode, either for testing or especially for debugging? Are instructions available for modifying the launch.json or creating a new one?
How do we pass command line arguments in VSCode, either for testing or especially for debugging? Are instructions available for modifying the launch.json or creating a new one?
Re: Quick tutorial for setting up VSCode for AHK
for v2, install thqby.vscode-autohotkey2-lsp and zero-plusplus.vscode-autohotkey-debug
Open the ahk file, and right-click menu select Debug Script with Params.
Open the ahk file, and right-click menu select Debug Script with Params.
Re: Quick tutorial for setting up VSCode for AHK
Thanks boiler for the quick guide and others for suggesting useful plugins.
Is there a way to make a table of contents for an AHK file in VSCode? I'm approaching 600 lines in my AHK file and it's a bit wieldy scrolling up and down. It'd be nice if I can specify an outline/table of contents that can be folded/unfolded. The default Outline pane in VSCode isn't very helpful because it just lists all the keys.
Is there a way to make a table of contents for an AHK file in VSCode? I'm approaching 600 lines in my AHK file and it's a bit wieldy scrolling up and down. It'd be nice if I can specify an outline/table of contents that can be folded/unfolded. The default Outline pane in VSCode isn't very helpful because it just lists all the keys.
Re: Quick tutorial for setting up VSCode for AHK
To quickly and easily launch my scripts, I wrote a script that I named: V2_AHK_Script_Launcher.ahk
This script works in AHK V2 version. This is a GUI that launches automatically when Windows opens.
This GUI allows me to launch any of my scripts with a "Double Click", regardless of whether it is written in V1 or V2.
As my scripts are divided into two folders, "Desktop or Documents", I added the two corresponding tabs.
I also added a third tab to also access my "Python" scripts.
The GUI minimizes itself in the taskbar, after launching a script, and thus remains accessible at all times.
I am currently working on adding a "ContextMenu" which would allow you to choose between "Launch" or "Edit" the targeted script.
Ideally, this context menu would offer 4 choices: "Open - Edit in Scite4AHK - Edit in VSCode - Copy Full Path".
I built this script from example #3 at the bottom of the "ListView" page in the AutoHotkey.com V2 Documentation
Here is the link to this page: https://www.autohotkey.com/docs/v2/lib/ListView.htm#Examples Example #3
Here is also a copy of this script, without the "ContextMenu", since it is currently under construction.
To personalize it, simply modify the path of the 3 “Loop Files”, Lines 18, 29 and 39.
NB. ( \*.ahk ) and ( \*.py ) are used to filter the results, in order to display only files containing the extension (.ahk or .py).
Code: Select all
#Requires Autohotkey v2.0
#SingleInstance Force
; ^ =Ctrl - # =Win - ! =Alt - + =Shift
Gui1 := Gui()
RetrievedTitle := Gui1.Title
Gui1.SetFont("s12") ; Set a font size (12-point).
Gui1.Add("Text",, "Pick a file to launch from the list below.")
Tab := Gui1.AddTab3(, [" AHK Desktop Folder "," AHK Documents Folder "," Python Folder "])
; LV1
Tab.UseTab(1)
LV1 := Gui1.Add("ListView", "r20 w700", ["Name","In Folder","Size (KB)","Type"])
LV1.ModifyCol(1, 280) ; Auto-size each column to fit its contents.
LV1.ModifyCol(2, 270) ; Auto-size each column to fit its contents.
LV1.ModifyCol(3, 70) ; Make the Size column at little wider to reveal its header.
LV1.ModifyCol(4, 50,) ; Make the Size column at little wider to reveal its header.
Loop Files, "C:\Users\Claude\Desktop\AutoHotkey\*.ahk" ; Change UserName
LV1.Add(, A_LoopFileName, A_LoopFileDir, A_LoopFileSizeKB, A_LoopFileExt)
; LV2
Tab.UseTab(2)
LV2 := Gui1.Add("ListView", "r20 w700", ["Name","In Folder","Size (KB)","Type"])
LV2.ModifyCol(1, 280) ; Auto-size each column to fit its contents.
LV2.ModifyCol(2, 270) ; Auto-size each column to fit its contents.
LV2.ModifyCol(3, 70) ; Make the Size column at little wider to reveal its header.
LV2.ModifyCol(4, 50,) ; Make the Size column at little wider to reveal its header.
Loop Files, "C:\Users\Claude\Documents\AutoHotkey\Lib\*.ahk" ; Change UserName
LV2.Add(, A_LoopFileName, A_LoopFileDir, A_LoopFileSizeKB, A_LoopFileExt)
; LV3
Tab.UseTab(3)
LV3 := Gui1.Add("ListView", "r20 w700", ["Name","In Folder","Size (KB)","Type"])
LV3.ModifyCol(1, 280) ; Auto-size each column to fit its contents.
LV3.ModifyCol(2, 270) ; Auto-size each column to fit its contents.
LV3.ModifyCol(3, 70) ; Make the Size column at little wider to reveal its header.
LV3.ModifyCol(4, 50,) ; Make the Size column at little wider to reveal its header.
Loop Files, "C:\Users\Claude\Desktop\Script Python\*.py" ; Change UserName
LV3.Add(, A_LoopFileName, A_LoopFileDir, A_LoopFileSizeKB, A_LoopFileExt)
gui1.Show
; Events
LV1.OnEvent('DoubleClick', RunFile)
LV2.OnEvent('DoubleClick', RunFile)
LV3.OnEvent('DoubleClick', RunFile)
RunFile(LV, RowNumber)
{
FileName := LV.GetText(RowNumber, 1) ; Get the text of the first field.
FileDir := LV.GetText(RowNumber, 2) ; Get the text of the second field.
try
Run(FileDir "\" FileName)
catch
MsgBox("Could not open " FileDir "\" FileName ".")
WinMinimize()
}
- michaelbeijer
- Posts: 83
- Joined: 04 Oct 2014, 08:01
- Location: Hastings, UK.
- Contact:
Re: Quick tutorial for setting up VSCode for AHK
Thanks, it was very easy to change it from my previous SciTEAutoHotkey to VS Code in the Dash.lexikos wrote: ↑01 Sep 2022, 16:41If you install AutoHotkey v2, it will ask you which editor to use the first time you attempt to edit a script. VS Code should be detected automatically, so you can select it from the list. This list can also be accessed from the Dash at any time, to change the default editor.
Michael Beijer
Dutch-English technical translator
Hastings, United Kingdom
Email: michael[at]beijer.uk
Website: Beijer.uk
Terminology: Beijerterm.com
AHK-learning project: Beijer.bot
Proz profile: proz.com/profile/652138
LinkedIn: linkedin.com/in/michael-beijer
Dutch-English technical translator
Hastings, United Kingdom
Email: michael[at]beijer.uk
Website: Beijer.uk
Terminology: Beijerterm.com
AHK-learning project: Beijer.bot
Proz profile: proz.com/profile/652138
LinkedIn: linkedin.com/in/michael-beijer