VS Code Setup

Scripting and setups with Visual Studio Code (vscode) and AutoHotkey.
Robt800
Posts: 31
Joined: 16 May 2023, 05:09

VS Code Setup

Post by Robt800 » 30 Oct 2023, 09:23

Hi guys,

I am trying to setup a new install of VS Code. I have installed the extensions:
AutoHotKey Plus Plus
vscode-autohotkey-debug
When I try to run an example script I get the following error messages:

Code: Select all

"C:/Program Files/AutoHotkey/v2/AutoHotkey64.exe" /Debug=127.0.0.1:9002 /ErrorStdOut c:\PLC_Notes\AutoHotKey\Scripts\Siemens_Audit_Trail_Amalgamation\Audit_Trail_Combine_Comments.ahk
C:\PLC_Notes\AutoHotKey\Scripts\Siemens_Audit_Trail_Amalgamation\Audit_Trail_Combine_Comments.ahk:10 : ==> Function calls require a space or "(".  Use comma only between parameters.
     Specifically: FileSelectFile, AuditTrailFilePath , , , Select The Audit Trail File, Excel (*.csv)
AutoHotkey closed for the following exit code: 2
Debugging stopped
Obviously then nothing happens and the code stops running.
Could someone point me in the right direction (to say I'm a beginner with vs code is an understatement).

Thanks
Rob

User avatar
boiler
Posts: 16985
Joined: 21 Dec 2014, 02:44

Re: VS Code Setup

Post by boiler » 30 Oct 2023, 09:26

The error message shows you are running AHK v1 code but are trying to execute it with AHK v2. That problem is independent of the editor and extension unless you have the extension pointing only at the v2 binary and you actually have both v1 and v2 installed.

If you run a script coded with v2 syntax, it would work without error. Example:

Code: Select all

#Requires AutoHotkey v2.0
AuditTrailFilePath := FileSelect(,, 'Select The Audit Trail File', 'Excel (*.csv)')
MsgBox AuditTrailFilePath

Robt800
Posts: 31
Joined: 16 May 2023, 05:09

Re: VS Code Setup

Post by Robt800 » 30 Oct 2023, 10:53

Thanks very much for helping me with my noob mistake.

I have now installed v1.1.37.01 onto the laptop as well. If I open up my original script and change the language mode to AutoHotKey v1 - I get the following when trying to run it:
'runtime' must be a file path that exists.
Specified: "C:\Program Files\AutoHotKey\AutoHotKeyU64.exe"
Whilst looking through the vscode-autohotkey-debug it says I have to specify the runtime attribute in the launch.json

When I opened launch.json I am presented with:

Code: Select all

    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        
        {
            "type": "ahk2",
            "request": "launch",
            "name": "AutoHotkey v2 Debugger",
            "program": "${file}",
            "stopOnEntry": true
        }
    ],

}
I tried to add a second configuration for 'ahk':

Code: Select all

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        
        {
            "type": "ahk2",
            "request": "launch",
            "name": "AutoHotkey v2 Debugger",
            "program": "${file}",
            "stopOnEntry": true
        }
    ],
    [					;error here
        
        {
            "type": "ahk",
            "request": "launch",
            "name": "AutoHotkey v2 Debugger",
            "program": "${file}",
            "stopOnEntry": true
        }
    ],

}

but where I put the ';error here - there is a squiggly line indicating an error - hence I'm not sure of the syntax.

Hope I've made sense...
Thanks
Rob

User avatar
boiler
Posts: 16985
Joined: 21 Dec 2014, 02:44

Re: VS Code Setup

Post by boiler » 30 Oct 2023, 11:12

I'm not sure how you've installed v1, but it looks like you may be using two different extensions: .ahk and .ahk2. It's recommended that you use .ahk for both, which will let AHK run the appropriate version per the script details and/or the preferences you set. I recommend following the installation instructions here.

vmech
Posts: 357
Joined: 25 Aug 2019, 13:03

Re: VS Code Setup

Post by vmech » 30 Oct 2023, 12:49

boiler wrote:
30 Oct 2023, 09:26
That problem is independent of the editor and extension unless you have the extension pointing only at the v2 binary and you actually have both v1 and v2 installed.
I discover that AHK++ extension can't properly set required type of script version, even if the #Required Autohotkey v1.1 directive used in the script first line.
It always set Autohotkey v2 type at every new editor window opened.


I take my words back. I have discovered the source of the problem.
It is necessary to remove the *.ahk extension in Settings -> Files:Associations, and then version's auto-detection will start working correctly.
Please post your script code inside [code] ... [/code] block. Thank you.

Robt800
Posts: 31
Joined: 16 May 2023, 05:09

Re: VS Code Setup

Post by Robt800 » 31 Oct 2023, 04:25

Great stuff - thanks for the help - it now runs as expected.
Thanks again
Rob

Post Reply

Return to “Visual Studio Code”