AutoHotkey commands

In AutoHotkey v2 every built-in action is called like a function, whether or not you keep a return value. What used to be a comma-separated command line is now a name followed by its arguments.

Keyboard and mouse

NamePurposeExample
SendType keystrokesSend "Hello{Enter}"
SendTextType literally, ignoring key namesSendText "a^b{c}"
ClickMouse click at a positionClick 400, 300
MouseMoveMove the pointerMouseMove 100, 100
HotkeyCreate or change a hotkey at runtimeHotkey "^j", MyAction

Programs and windows

NamePurposeExample
RunStart a program, file or URLRun "notepad.exe"
RunWaitStart it and wait for it to finishRunWait "cmd /c build.bat"
WinActivateBring a window to the frontWinActivate "ahk_exe notepad.exe"
WinWaitPause until a window existsWinWait "Untitled - Notepad"
WinMoveMove or resize a windowWinMove 0, 0, 800, 600, "A"
WinCloseClose a windowWinClose "A"

Messages and timing

NamePurposeExample
MsgBoxShow a dialogMsgBox "Done"
ToolTipShow a small floating noteToolTip "Working…"
InputBoxAsk for a valuename := InputBox("Your name?").Value
SleepWait in millisecondsSleep 250
SetTimerRun something on a scheduleSetTimer Check, 5000

Putting a few together

#Requires AutoHotkey v2.0

^!r::
{
    Run "notepad.exe"
    WinWait "ahk_exe notepad.exe"
    WinActivate "ahk_exe notepad.exe"
    Send "Meeting notes{Enter}"
    Send FormatTime(A_Now, "MMMM d, yyyy")
}

WinWait is what makes this reliable: without it the keystrokes can arrive before the window is ready.

Reading the syntax

Arguments in the manual are written in order, with optional ones in square brackets. Anything textual needs quotes; numbers and variables do not. Values that come back — a window title, a clipboard string, a dialog result — are captured with :=.

Reusable logic of your own belongs on the functions page, and complete programs are collected under examples.

Frequently asked questions

How do I use AutoHotkey commands in v2?

Call them like functions: the name followed by arguments, with text in quotes, for example Run "notepad.exe".

What is the difference between Send and SendText?

Send interprets braces and modifier symbols as keys, while SendText types the string exactly as written.

How do I wait for a program to open?

Follow Run with WinWait, then act on the window once it exists.


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