Visual Studio Code Support

Scripting and setups with Visual Studio Code (vscode) and AutoHotkey.
User avatar
haichen
Posts: 631
Joined: 09 Feb 2014, 08:24

Visual Studio Code Support

31 Dec 2015, 07:13

After the nice work with Atom, i thought it would be also nice to run AutoHotkey from Visual Studio Code. I found an extension for syntax highlighting and here is how i got it working:

In VSC type
1. strg+p
2. ?
3. klick ext install
4. type autohotkey
klick on install

After restart of VSC it says there is an issue with this extension.
But nevertheless i could get it working by downloading the extension from
https://github.com/stef-levesque/vscode ... master.zip
Then i copied the files in the zip in the VSC extension dir:
C:\Users\user\.vscode\extensions\slevesque.vscode-autohotkey-0.0.1
After a restart i got the syntaxhiglighting.

At second i wanted to run a script from VSC. After searching i tried the extension "Runner" from
Yasuhiro Matsumoto

As above type
1. STRG+P
2. ?
3. klick ext install
4. type runner
klick on install

After this you have to open the menu File>Preferences>User Settings.
This menu shows the Default Settings at the left and the file settings.json at the right where you have to copy

Code: Select all

{
    "runner.languageMap": {"autohotkey": "C:/Program Files/AutoHotkey/autohotkey.exe"},
    "runner.extensionMap": {"ahk": "autohotkey"},
}
After saving try to run (STRG+SHIFT+R) a test.ahk with

Code: Select all

loop, 10
  FileAppend , x:=%a_index%`n, *
You get the text in an ouput column in VSC.
Zeb

Re: Visual Studio Code Support

28 Sep 2016, 05:40

Even tho this Post is probably too old to hope for a reply but I can't get it to execute my scripts. It says "autohotkey" was either wrong written or couldn't be found.
User avatar
haichen
Posts: 631
Joined: 09 Feb 2014, 08:24

Re: Visual Studio Code Support

30 Sep 2016, 02:51

I saw it yesterday. Meanwhile I've a new pc. So I had to to install VSC and try my own Tip. But it also didn't work for me and until now I found no solution. Sorry!
Zeb

Re: Visual Studio Code Support

25 Oct 2016, 08:54

Well after checking the source-code of the extension and not finding anything suspicious... I simply tried out the fullpath for the autohotkey.exe plus double-double-quotes, which does the job.
Seems kind-of stupid but I don't care as long as it works that way.

Code: Select all

{
    "runner.languageMap": {"autohotkey": "C:/Program Files/AutoHotkey/autohotkey.exe"},
    "runner.extensionMap": {"ahk": ""C:/Program Files/AutoHotkey/autohotkey.exe""},
}
User avatar
haichen
Posts: 631
Joined: 09 Feb 2014, 08:24

Re: Visual Studio Code Support

25 Oct 2016, 11:59

oh wow, very strange! Thank you very much for finding this!!
momo2000
Posts: 32
Joined: 25 Jan 2015, 12:00

Re: Visual Studio Code Support

11 Nov 2016, 08:44

Trying to get VSC working with AHK as well. Syntax highlighting works, but the Run/debug feature does not. I followed the steps above (and put those two lines in the settings.json file) but not working. When I got to run/debug, I get the error "Cannot find runtime 'node' on PATH." Any ideas?
mh1723
Posts: 1
Joined: 08 Jan 2017, 21:47

Re: Visual Studio Code Support

08 Jan 2017, 22:03

I am very new to all this but very interested in also setting it up. Every time I have come across a not found in PATH type issue it stems from not having one file or another properly set in the system environmental variables. From the System window or right click start button->system->advanced system settings->Environment Variables. Include the paths for everything AHK related.

At times I have had to go down a few levels in a directory and select another folder in order for it to pick it up correctly.
User avatar
haichen
Posts: 631
Joined: 09 Feb 2014, 08:24

Re: Visual Studio Code Support

10 Feb 2017, 08:35

I tried another try to get "runner" to run but failed.

So i now try another "Code Runner". This Extension works and so want to share it with you.

https://marketplace.visualstudio.com/it ... ode-runner

Installation:
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
ext install code-runner

After Installation you have to add the following to the menu File>Preferences>User Settings
(You may leave or change all other "executors" from the example but i take here only autohotkey related):

Code: Select all

{
    "code-runner.executorMap": {
        "autohotkey": "\"C:\\Program Files\\AutoHotkey\\AutoHotkey.exe\"",
    },
    "code-runner.defaultLanguage": "autohotkey",
    "code-runner.executorMapByFileExtension": {
        ".ahk": "\"C:\\Program Files\\AutoHotkey\\AutoHotkey.exe\""
    }
}
Right click - "Run Code" and autohotkey runs the whole script or the marked text.
Stenemo
Posts: 9
Joined: 25 Dec 2015, 04:48
Contact:

Re: Visual Studio Code Support

23 Apr 2017, 05:53

Are there any ongoing projects to make this available for Visual Studio 2017 as well?
User avatar
J Scott Elblein
Posts: 7
Joined: 21 Aug 2017, 05:19
Location: Chicago
Contact:

Re: Visual Studio Code Support

01 Sep 2017, 23:08

Not exactly sure what I'm missing here; seems like it should work but, I still get the error, when trying to run a script:
[Running] autohotkey "g:\FileMenuTools\App\FileMenu Tools\My Custom Additions\Coding\Scripting\AutoHotKey\My Scripts\tempCodeRunnerFile.ahk"
'autohotkey' is not recognized as an internal or external command,
operable program or batch file.
I have Code Runner installed, and I opened the settings file, and added this exactly:

Code: Select all

{
    "code-runner.executorMap": {
        "autohotkey": "\"G:\\FileMenuTools\\App\\FileMenu Tools\\My Custom Additions\\Coding\\Scripting\\AutoHotKey\\AutoHotkeyU64.exe\""
    },

    //"code-runner.defaultLanguage": "autohotkey",
    "code-runner.executorMapByFileExtension": {
        ".ahk": "\"G:\\FileMenuTools\\App\\FileMenu Tools\\My Custom Additions\\Coding\\Scripting\\AutoHotKey\\AutoHotkeyU64.exe\""
    }
}
NOTE: I commented out the .defaultlanguage line because I don't want to set CR to use AHK as the default language (still new to both VSCode, and AHK, and also CR, so maybe I'm misunderstanding that line?), but either way, even when I don't comment that line out, I still get the same error.

I also restart VSCode between each change, just to be sure it "took".

Anyone able to point out the problem?

Update:

Scratch that; not exactly sure why, since reloading the entire app didn't allow it to work, but after adding another extension, and then pressing the "reload" button for that extension after it was installed, somehow got ahk to work in CR. :facepalm:
icuurd12b42
Posts: 202
Joined: 14 Aug 2016, 04:08

Re: Visual Studio Code Support

08 Sep 2017, 18:03

I got the Highlighting working. As for the runner bit and how to run a ahk file from the IDE I got no clue

and psst: https://autohotkey.com/boards/viewtopic ... 26#p169526
User avatar
haichen
Posts: 631
Joined: 09 Feb 2014, 08:24

Re: Visual Studio Code Support

09 Sep 2017, 05:07

Mostly I use SciTE4AutoHotkey or Notepad2 but occasionally I try Visual Studio Code.
Now I found how to get Code-Runner working again. The difference to my settings above (which worked some time) is changing autohotkey to ahk in the .executorMap.

This works for me:

Code: Select all

{
    "code-runner.executorMap": {
        "javascript": "node",
        "php": "C:\\php\\php.exe",
        "python": "python",
        "perl": "perl",
        "ruby": "C:\\Ruby23-x64\\bin\\ruby.exe",
        "go": "go run",
        "html": "\"C:\\Program Files\\Mozilla Firefox\\firefox.exe\"",
        "java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
        "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "ahk": "\"C:\\Program Files\\AutoHotkey\\AutoHotkey.exe\""
    },
    "code-runner.defaultLanguage": "ahk",
    "code-runner.executorMapByFileExtension": {
        ".ahk": "\"C:\\Program Files\\AutoHotkey\\AutoHotkey.exe\""
    }
}
Intellisense works for autohotkey! Nice.
User avatar
J Scott Elblein
Posts: 7
Joined: 21 Aug 2017, 05:19
Location: Chicago
Contact:

Re: Visual Studio Code Support

07 Oct 2017, 10:22

Seems everything works great so far; intellisense, syntax highlighting, and running the code with code runner. Only problem left (for me at least) is actually being able to set breakpoints, and debug as you would line by line, (etc.).

Anyone else have the same problem?
User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: Visual Studio Code Support

18 Oct 2017, 14:45

haichen wrote:Now I found how to get Code-Runner working again. The difference to my settings above (which worked some time) is changing autohotkey to ahk in the .executorMap.
Thanks for this. I was frustrated with why the previous settings weren't working for me, but it works now. This along with the other features mentioned above (as well as GotoTilla, mentioned below) make it a pretty nice AHK editor. I'm liking it.
J Scott Elblein wrote:Seems everything works great so far; intellisense, syntax highlighting, and running the code with code runner. Only problem left (for me at least) is actually being able to set breakpoints, and debug as you would line by line, (etc.).

Anyone else have the same problem?
I didn't think any debugging extensions have been implemented for AHK yet. Am I wrong about that?

By the way, GoToTilla, a tool for jumping directly to your functions, labels, hotkeys, and hotstrings (similar to TillaGoto in SciTE4AutoHotkey) works great in Visual Studio Code. Use the update by hoppfrosch at the bottom of the linked page.
User avatar
J Scott Elblein
Posts: 7
Joined: 21 Aug 2017, 05:19
Location: Chicago
Contact:

Re: Visual Studio Code Support

12 Nov 2017, 16:18

I didn't think any debugging extensions have been implemented for AHK yet. Am I wrong about that?
Looks that way, unfortunately. I'm pretty surprised actually. Seems like AHK is popular enough that someone would've felt the need for breakpoints, reading live vars, etc., and already made a vscode extension to debug ahk scripts. :wtf:

After reading the AHK help, it looks like this would work in vscode, but, I just don't have the time to implement it myself. Hopefully someone with some time would take the initiative. *praying emoticon*
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: Visual Studio Code Support

11 Oct 2018, 00:38

haichen wrote:I tried another try to get "runner" to run but failed.

So i now try another "Code Runner". This Extension works and so want to share it with you.

https://marketplace.visualstudio.com/it ... ode-runner

After Installation you have to add the following to the menu File>Preferences>User Settings
(You may leave or change all other "executors" from the example but i take here only autohotkey related):

Code: Select all

{
    "code-runner.executorMap": {
        "autohotkey": "\"C:\\Program Files\\AutoHotkey\\AutoHotkey.exe\"",
    },
    "code-runner.defaultLanguage": "autohotkey",
    "code-runner.executorMapByFileExtension": {
        ".ahk": "\"C:\\Program Files\\AutoHotkey\\AutoHotkey.exe\""
    }
}
The above code appears incorrect or outdated. What seems to work correctly is the below. Note- there are A32, U32, and U64 versions of AutoHotkey that can be found in C:\Program Files\AutoHotkey folder, so you might want to change AutoHotkey.exe to AutoHotkeyU64.exe, for example. If AutoHotkey is installed on a different drive and directory, then you need to make the changes to reflect that. After editing the USER SETTINGS by copying and pasting the below code, you must save your changes, before checking to see if it works. Just attempt to close USER SETTINGS and a message box will pop up asking you if you want to save changes.

Code: Select all

{
"code-runner.executorMap": {
    "ahk": "\"C:\\Program Files\\AutoHotkey\\AutoHotkey.exe\"",
    },    
"code-runner.executorMapByFileExtension": {
    "ahk": "\"C:\\Program Files\\AutoHotkey\\AutoHotkey.exe\"",
    },
}
I like AHK Studio w/ AutoGUI better (obviously specialized), but can see those programmers that know or use multiple languages wanting to use VSC.
User avatar
hoppfrosch
Posts: 443
Joined: 07 Oct 2013, 04:05
Location: Rhine-Maine-Area, Hesse, Germany
Contact:

Re: Visual Studio Code Support

21 Jun 2019, 04:44

An alternative to Code Runner to run ahk-files from within VSCode, might be using Tasks.

To get this running, do the following:
  • Create a subfolder named .vscode within your working directory
  • Create a file named tasks.json within folder .vscode
  • Put the following contents into tasks.json

    Code: Select all

    {
    	// See https://go.microsoft.com/fwlink/?LinkId=733558
    	// for the documentation about the tasks.json format
    	"version": "2.0.0",
    	"tasks": [
    		{
    			"label": "Run the AHK-file",
    			"type": "shell",
    			"script": "C:/programme/autohotkey/autohotkey.exe ${file}",
    			"windows": {
    				"command": "C:\\Programme\\autohotkey.exe ${file}"
    			},
    			"presentation": {
    				"panel": "shared"
    			},
    			"group": {
    				"kind": "test",
    				"isDefault": true
    			},
    			"options": {
    				"cwd": "${fileDirname}"
    			}
    		}
    	]
    }
    


You can run the task as described here. You might consider using extension Task Runner as well
User avatar
rediffusion
Posts: 58
Joined: 15 Mar 2019, 05:16

Re: Visual Studio Code Support

17 Dec 2019, 17:43

Json to default - File > Preferences > Settings > in the search field, we're writing :
o Settings > Workbench > Settings: Editor > ui change to json
o Settings use split json > tick the box (split editor use).
> Display UI – Ctrl+Shift+P > Preferences: Open Settings (UI).
> Display Json – Ctrl+Shift+P > Preferences: Open Settings (Json).

To run "AutoHotkey" script my `User Settings` looks like this:

Code: Select all

{
    "python.pythonPath": "C:\\Users\\USER\\Anaconda3",
    "editor.renderControlCharacters": false,
    "markdownlint.customRules": [
        "{docsmsft.docs-markdown}/markdownlint-custom-rules/rules.js"
    ],
    "workbench.colorTheme": "Monokai Dimmed",
    "markdownlint.config": {
        "MD025": {
            "front_matter_title": ""
        }
    },
    "window.zoomLevel": 0,
    "editor.fontSize": 17
    "[typescript]": {
        "editor.defaultFormatter": "vscode.typescript-language-features"
    },
    "[html]": {
        "editor.defaultFormatter": "vscode.html-language-features"
    },
    "[css]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "[javascript]": {
        "editor.defaultFormatter": "vscode.typescript-language-features"
    },
    "editor.wordWrap": "on",
    "files.encoding": "utf8bom",
    "[markdown]": {},
    "workbench.settings.useSplitJSON": true,
    "code-runner.runInTerminal": false
    "code-runner.saveFileBeforeRun": true,
    "code-runner.executorMap": {
        "ahk": "\"C:\\Program Files\\AutoHotkey\\AutoHotkey.exe\"",
        },    
    "code-runner.executorMapByFileExtension": {
        "ahk": "\"C:\\Program Files\\AutoHotkey\\AutoHotkey.exe\"",
        },
}
:idea: I've had one day's headache. I think it will be useful to know, enjoy!
User avatar
rediffusion
Posts: 58
Joined: 15 Mar 2019, 05:16

Re: Visual Studio Code Support

19 Dec 2019, 21:48

@hoppfrosch

Task Runner isn't working! This is what I see in Terminal: :beard:

Code: Select all

> Executing task in folder Tasks for AutoHotkey: C:\Programme\autohotkey.exe c:\Users\USER\Downloads\DD\Visual Studio\Visual Studio Code\TEST-Folder\Tasks for AutoHotkey\test.ahk <

C:\Programme\autohotkey.exe : Name "C:\Programme\autohotkey.exe" is not recognized as the name of a commandlet, function, script file, or program being executed. Check that the name is spelled correctly, and that the path is present and correct, then try again.
line:1 sign:1
+ C:\Programme\autohotkey.exe c:\Users\USER\Downloads\DD\Visua ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Programme\autohotkey.exe:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.
Tasks/Task Runner such as for compiling in .exe Am I right?

This is the first time I understood how the task file actually gets things done. Although there are easier ways to do it, for example, the Code Runner extension, but using this method would help anyone in the future when they try to setup visual studio for other languages.
Also for `AutoHotkey` there's a nice plugin "Autohotkey Manager" with features:
[*] Compile Script
[*] Run Script
[*] Kill Exe/Script
[*] Run Selected Text
autocart
Posts: 214
Joined: 12 May 2014, 07:42

Re: Visual Studio Code Support

22 Apr 2020, 06:09

hoppfrosch wrote:
21 Jun 2019, 04:44
An alternative to Code Runner to run ahk-files from within VSCode, might be using Tasks.

...

You can run the task as described here. You might consider using extension Task Runner as well
For future reference:
This worked for me, as soon as I made these adaptions:

Code: Select all

{
	// See https://go.microsoft.com/fwlink/?LinkId=733558
	// for the documentation about the tasks.json format
	"version": "2.0.0",
	"tasks": [
		{
			"label": "Run the AHK-file",
			"type": "shell",
			"command": "C:/programme/autohotkey/autohotkey.exe \"${file}\"",
			"windows": {
				"command": "C:\\Programme\\autohotkey\\autohotkey.exe \"${file}\""
			},
			"presentation": {
				"panel": "shared"
			},
			"group": {
				"kind": "test",
				"isDefault": true
			},
			"options": {
				"cwd": "${fileDirname}"
			}
		}
	]
}
I ...
  • changed "script" to "command"
  • put \" around both &{file} variables/placeholders
  • added the folder autohotkey to the windows-path
What I did not figure out was how to make the command execute IF the path to the command contains spaces as well. Futunately, I am on a German Windows and the exe itself is in the standard x64 programs' folder and does not have spaces. So, I am lucky that it works for me. For those on an English version of Windows, I am sorry, but I don't know how to do it.
Regards, me

Return to “Visual Studio Code”

Who is online

Users browsing this forum: No registered users and 6 guests