AHK v1 -> v2 script converter
This script will attempt to convert a script written in AHK v1 to the correct syntax so that it works in AHK v2.
It is useful to quickly convert some of the bigger syntax changes. Afterwards you can investigate the converted version for other minor changes that the converter didn't cover.
I took Frankie's original converter linked below, and updated it to work with the latest AHK v2 alpha build.
I've also added essential unit tests using the Yunit framework to encourage contributions from others.
However, this project is way more ambitious that I originally thought, and it needs a lot of work. See below for how you can contribute.
QuickConvertorV2.ahk
file with AHK V2v2converter.ahk
script with AHK v2scriptfile.ahk
written for AHK v1.scriptfile_newV2.ahk
in the same directory
Use v2converter.ahk -h
in cmd to use the CLI
You can modify parts of how the script behave from editing variables inside the scriptThe AutoHotKey Exe\AutoHotKeyV2.exe
file (as well as the tests\Tests.exe
file) is simply a renamed copy of the AutoHotkey32.exe
(v2.0.11) interpreter file. The interpreter alone does nothing without passing a script to it. But here, we take advantage of the default scriptfile feature where the Tests.exe
file will look for a file named Tests.ahk
and automatically run it. You can make changes to the .ahk
file and then just run the .exe
. The reason for doing this is because most people will still have AHK v1 installed and associated with *.ahk
files. So it would be inconvenient to run this converter without some workarounds. Likewise, the diff\VisualDiff.exe
file (as well as the AutoHotKey Exe\AutoHotKeyV1.exe
file) is just a renamed AutoHotkeyU32-v1.1.24.02.exe
The converter is not complete. That is, it does not detect all things that need to be changed to make sure the script works in v2. However, for the things that it DOES change, everything should hopefully work, except for the following. Here are the instances that are known to fail:
IfEqual, var, value, Sleep, 500
. The unit tests for those unescaped commas are commented out.There is a lot of work to do and many commands and functions that still need to be changed. There are also many edge cases when trying to parse script code and convert it. Of course, whenever making changes to the code, you should be constantly running the unit tests to confirm that things are still working. First run QuickConvertorV2.ahk
with Settings -> Testmode
on, make sure no tests fail. Then run the tests\Tests.exe
file and pray for green.
Here are a few ways you can help:
StringTrimRight
. Follow the existing format in the tests\Tests.ahk
file.And of course, create a Pull Request with your changed code