AutoHotkey v2

AutoHotkey v2 is the current release line, and it is the version worth learning if you are starting today. The rewrite removed most of the guesswork in the old syntax: text is quoted, variables are not, and every command call follows the same shape as a function call.

What changed from v1.1

Topicv1.1v2
Assignmentx = text or x := "text"Always x := "text"
CallingMsgBox, HelloMsgBox "Hello"
ConcatenationPercent signs around variablesValues written next to each other
BlocksLabels with returnBraces after the hotkey
ErrorsOften silentThrown, so problems surface early

The shape of a v2 script

#Requires AutoHotkey v2.0

count := 0

^!c::
{
    global count
    count += 1
    MsgBox "Pressed " count " time(s)"
}

The #Requires line is worth keeping at the top of everything you write. It stops a v2 script from being launched by a v1 interpreter and producing confusing errors.

Values, arrays and maps

tools := ["editor", "terminal", "browser"]
paths := Map("home", "C:\Users", "temp", "C:\Temp")

for item in tools
    MsgBox item

MsgBox paths["temp"]

Arrays hold an ordered list and start at index 1; maps hold named entries. Both are read with square brackets.

Converting an old script

There is no switch that makes a v1 script run under v2. Work through it line by line: quote the literal text, replace comma-style calls, wrap multi-line hotkeys in braces, and re-check any function whose parameters were reordered. Short scripts usually take minutes; long ones are often faster to rewrite around the same idea.

Learning path

Read the v2 reference for the formal definitions, work through the tutorials for guided practice, then browse examples and scripts to see the language used at full size. The commands and functions pages explain how the built-in library is grouped.

Frequently asked questions

What is AutoHotkey v2?

The current release line of the language, with a consistent expression syntax, quoted strings, brace-delimited hotkey blocks and errors that are thrown instead of ignored.

Can I run v1 scripts under AutoHotkey 2?

Not directly. The syntax changed, so a v1 script has to be converted before it will run under v2.

Should a beginner start with v2?

Yes. New material, new libraries and this site's examples all target v2.


AutoHotkeyTools.com is an independent Windows resource covering AutoHotkey tools, scripts, hotkeys, tutorials and desktop automation. It is not affiliated with the AutoHotkey project.