Scripting Language

Table of Contents

General Conventions

; This entire line is a comment.
Run Notepad; This is a comment on the same line as a command.
/* MsgBox, This line is commented out (disabled). MsgBox, Common mistake: */ this does not end the comment. MsgBox, This line is commented out. */


Strings / Text


MsgBox % Format("You are using AutoHotkey v{1} {2}-bit.", A_AhkVersion, A_PtrSize*8)


Function Calls

Operators for Objects

Expression Statements

Legacy Syntax

Send, The time is %A_Hour% o'clock.
Clipboard = This text is copied to the clipboard.
If Var = Text value


MsgBox, The time is %A_Hour% o'clock.

OutputVar and InputVar Parameters

; Replace all spaces with pluses: StringReplace, NewStr, OldStr, %A_Space%, +, All

Text Parameters

MsgBox, The time is %A_Hour% o'clock.

Numeric Parameters

Sleep %n%000; Sleep for n seconds. Sleep %m%; Sleep for m milliseconds.

% Expression

Sleep MillisecondsToWait Sleep %MillisecondsToWait% Sleep % MillisecondsToWait

Documentation Conventions

StringLower, OutputVar, InputVar , T

Optional Parameters

Run, notepad.exe, C:\ Run, notepad.exe,, Min Run notepad.exe, , , notepadPID

Expressions vs Legacy Syntax

MsgBox % 1+1; Shows "2" MsgBox 1+1; Shows "1+1"
MsgBox % "This is text." MsgBox This is text.
MsgBox % A_AhkVersion MsgBox %A_AhkVersion%
MsgBox % "Hello %A_UserName%."; Shows "%A_UserName%" MsgBox Hello %A_UserName%.; Shows your username.
MsgBox % "Hello " . A_UserName . "."; Shows your username.
MsgBox % Format("Hello {1}.", A_UserName); {} also works in place of {1}.
MyVar := "This is text." MyVar = This is text.if (Var1 = Var2) if Var1 = %Var2%
if (Var1 >= Low and Var1 <= High) if Var1 between %Low% and %High%

Different Equals

Total = A + B; Assigns the literal text "A + B"

Commands vs Functions

Control Flow Statements

Control Flow vs Commands

If Statement

Loop Statement

t := "column 1`tcolumn 2`nvalue 1`tvalue 2" Loop Parse, t, `n { rowtext := A_LoopField rownum := A_Index; Save this for use in the second loop, below. Loop Parse, rowtext, `t { MsgBox %rownum%:%A_Index% = %A_LoopField% } }

Not Control Flow

Structure of a Script

Auto-execute Section


gosub Label1 Label1: MsgBox %A_ThisLabel% return

User-Defined Functions

MyFunction(FirstParameter, Second, ByRef Third, Fourth:="") { ... return "a value" }



Dynamic Variables

target := 42 second := "target" MsgBox %second%; Normal (single) variable reference in text => target MsgBox % second; Normal (single) variable reference in an expression => target MsgBox % %second%; Double-deref in an expression => 42
MyArray1 = A MyArray2 = B MyArray3 = C Loop 3 MsgBox % MyArray%A_Index%; Shows A, then B, then C.
SysGet, WA, MonitorWorkArea MsgBox, Left: %WALeft% -- Top: %WATop% -- Right: %WARight% -- Bottom: %WABottom%.





Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store