r/CodeToolbox • • Feb 19 '26

AutoHotkey v1 → v2 Translation Guide

This guide shows how to convert v1 scripts into v2 safely and correctly.

⸻

  1. The Most Important Rule

In v2, commands became functions.

v1 used command syntax:

MsgBox Hello World

v2 uses function syntax:

MsgBox("Hello World")

This applies to most of AutoHotkey.

⸻

2. Variables: Remove percent signs

v1

name := "John"

MsgBox %name%

v2

name := "John"

MsgBox(name)

Rule:

•	v1 uses %variable%

•	v2 uses variable

⸻

3. Assignment vs legacy assignment

v1 allowed two assignment styles.

v1 (legacy — avoid)

name = John

v1 (expression — correct)

name := "John"

v2 (only this works)

name := "John"

⸻

4. IF statements

v1

if name = John

MsgBox Match

v2

if (name = "John")

MsgBox("Match")

Always use parentheses.

⸻

5. MsgBox translation

v1

MsgBox Hello

MsgBox %name%

MsgBox, 64, Title, Message

v2

MsgBox("Hello")

MsgBox(name)

MsgBox("Message", "Title", 64)

Parameter order changed:

v1: MsgBox, options, title, text

v2: MsgBox(text, title, options)

⸻

6. InputBox translation

v1

InputBox, name, Title, Enter name

MsgBox %name%

v2

name := InputBox("Enter name", "Title")

MsgBox(name.Value)

v2 returns an object.

⸻

7. Send command

v1

Send Hello

v2

Send("Hello")

⸻

8. Sleep

v1

Sleep 1000

v2

Sleep(1000)

⸻

9. Run programs

v1

Run notepad.exe

v2

Run("notepad.exe")

⸻

10. WinActivate

v1

WinActivate Untitled - Notepad

v2

WinActivate("Untitled - Notepad")

⸻

11. Hotkeys

Basic hotkeys stay similar.

v1

F1::

MsgBox Hello

return

v2

F1::

{

MsgBox("Hello")

}

Braces are recommended.

⸻

12. Functions

v1

MyFunction()

{

MsgBox Hello

}

v2

MyFunction()

{

MsgBox("Hello")

}

Main difference: MsgBox now needs parentheses.

⸻

13. Arrays

v1

arr := []

arr.Push("Apple")

MsgBox % arr[1]

v2

arr := []

arr.Push("Apple")

MsgBox(arr[1])

⸻

14. Loops

v1

Loop 5

{

MsgBox %A_Index%

}

v2

Loop 5

{

MsgBox(A_Index)

}

⸻

15. FileRead

v1

FileRead, content, file.txt

MsgBox %content%

v2

content := FileRead("file.txt")

MsgBox(content)

⸻

16. FileAppend

v1

FileAppend Hello, file.txt

v2

FileAppend("Hello", "file.txt")

⸻

17. ExitApp

v1

ExitApp

v2

ExitApp()

⸻

18. String concatenation

v1

full := first . " " . last

v2

full := first " " last

Dot is optional now.

⸻

19. SetTimer

v1

SetTimer, MyLabel, 1000

MyLabel:

MsgBox Hello

return

v2

SetTimer(MyFunction, 1000)

MyFunction()

{

MsgBox("Hello")

}

Labels replaced by functions.

⸻

20. GUI conversion example

v1

Gui, Add, Text,, Name:

Gui, Add, Edit, vName

Gui, Show

return

v2

gui := Gui()

gui.Add("Text",, "Name:")

gui.Add("Edit", "vName")

gui.Show()

GUI became object-based.

⸻

21. Labels → Functions

v1 used labels.

v1

MyLabel:

MsgBox Hello

return

v2 uses functions:

MyFunction()

{

MsgBox("Hello")

}

⸻

22. Return values

v1:

return value

v2:

return value

Same, but functions are more important now.

⸻

23. Common conversion table (quick reference)

v1 v2

MsgBox Hello MsgBox(“Hello”)

Sleep 1000 Sleep(1000)

Run notepad.exe Run(“notepad.exe”)

WinActivate Title WinActivate(“Title”)

FileRead, x, file.txt x := FileRead(“file.txt”)

FileAppend text, file.txt FileAppend(“text”, “file.txt”)

Send Hello Send(“Hello”)

ExitApp ExitApp()

⸻

24. Complete example conversion

v1 script

F1::

InputBox, name, Enter Name, What is your name?

MsgBox Hello %name%

return

v2 script

F1::

{

result := InputBox("What is your name?", "Enter Name")

if (result.Result = "OK")

{

MsgBox("Hello " result.Value)

}

}

⸻

25. Migration checklist

When converting a script:

Step 1: Add parentheses to commands

Step 2: Remove %variable%

Step 3: Convert FileRead/FileAppend

Step 4: Convert labels to functions

Step 5: Fix GUI code

Step 6: Test script

Step 7: Fix errors

⸻

26. Fast mechanical conversion pattern

Search → Replace:

MsgBox → MsgBox(

Sleep → Sleep(

Run → Run(

Send → Send(

WinActivate → WinActivate(

FileAppend → FileAppend(

FileRead → FileRead(

Then add closing ) manually.

⸻

27. Most common migration errors

Error:

This variable has not been assigned a value

Fix:

Initialize variable:

name := ""

⸻

Error:

Too many parameters

Fix:

Use correct function format.

⸻

Recommended appendix title for your book

Appendix A — Complete AutoHotkey v1 to v2 Migration Translation Guide

Enjoy it John Nunez

1 Upvotes

0 comments sorted by