AutoHotkey tutorials

Each tutorial below is short on purpose: one idea, one working file, one thing you can keep using afterward. Work through them in order if you are new, or jump to whichever problem you have right now.

1. Set up in five minutes

  1. Install AutoHotkey v2 on your Windows 11 or Windows 10 machine.
  2. Create first.ahk and open it in any text editor.
  3. Paste #Requires AutoHotkey v2.0 on the first line.
  4. Add ^!n::Run "notepad.exe" and save.
  5. Double-click the file, then press Ctrl+Alt+N.

2. Your first hotkey

Start from a single key, then grow the block. The writing hotkeys page in the reference walks through modifiers, multi-line blocks and context sensitivity in detail; the hotkeys page here summarizes the symbols.

3. Send keystrokes to another program

^!s::
{
    WinActivate "ahk_exe notepad.exe"
    WinWaitActive "ahk_exe notepad.exe"
    Send "Status report{Enter}"
}

Activate first, wait for the window to accept focus, then type. Skipping the wait is the single most common reason keystrokes land in the wrong place.

4. Manage windows by rule

#Up::WinMaximize "A"
#Down::WinMinimize "A"
#c::WinClose "A"

5. Build a text expansion set

Collect the phrases you retype — addresses, sign-offs, ticket templates — into one hotstring file and load it at startup. Details and options are on the scripts page.

6. Repeat something on a schedule

SetTimer Remind, 1800000   ; every 30 minutes

Remind()
{
    ToolTip "Stand up and stretch"
    Sleep 3000
    ToolTip
}

7. Find out why a script misbehaves

When the basics feel comfortable, read the v2 guide and start reading finished code under examples.

Frequently asked questions

How do I write my first AHK script?

Create a .ahk file, add #Requires AutoHotkey v2.0 and one hotkey line, save it, and double-click to run.

Why do my keystrokes go to the wrong window?

The script typed before the target window had focus. Activate the window, wait with WinWaitActive, then send.

How do I run a task every few minutes?

Use SetTimer with a function name and an interval in milliseconds.


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