AutoHotkey Tutorial

By Xah Lee. Date: . Last updated: .

AutoHotkey logo nz9fX

AutoHotkey is a keyboard macro software for Microsoft Windows. It is free.

For example, you can:

Download AutoHotkey

Download at

Create Script

To create a AHK script, type the following text into a file, save and name it test.ahk

; launch Notepad
Run Notepad

AutoHotkey language words are not case sensitive. Run is the same as run.

Run Script

To run ahk script, double click it.

ahk script 2021-02-14
ahk script 2021-02-14

Exit AutoHotkey

ahk T2Y6Q
A running AutoHotkey script icon in Taskbar's System Notification Area.

Right click on the AutoHotkey icon and pull a menu to exit the script. If you exit, your hotkeys will not work anymore.

Launch App, Open File

; launch app by name
Run Notepad
; launch app by path
Run "C:\Windows\explorer.exe"
; open file
Run "%HOMEPATH%\Documents\todo.txt"
; open folder
Run "%HOMEPATH%\Documents"
; launch a app with a parameter
Run "%HOMEPATH%\Downloads\emacs-27.1-x86_64\bin\runemacs.exe" "-Q"

Set Key to Launch App

Here's how you create a keyboard shortcut for launching Notepad:

; make Win+n start Notepad
#n::Run Notepad

Save the above in a file. Then, double click on it. Then, pressing ❖ Window+n will launch Notepad.

More examples with different keys:

; assign a hotkey to launch a app
#n::Run Notepad     ; Win+n
!n::Run Notepad     ; Alt+n
^n::Run Notepad     ; Ctrl+n

F6::Run Notepad     ; F6
^F6::Run Notepad    ; Ctrl+F6
^!n::Run Notepad    ; Ctrl+Alt+n

Key Syntax

AutoHotkey Key Syntax

Sending Text and Keystrokes

You can define a hotkey, so that, when pressed, it sends some other typing or keystrokes.

; pressing F9 to insert your signature
Send Best,{Enter}{Enter} Mary Jane

Note that AutoHotkey does not support Unicode well as of 2021-02-14. That means, if the text you want to insert is Chinese, or emoji 😂 , it won't work.

Start AutoHotkey when Windows Starts

Windows: Add App to Auto Start

AutoHotkey mode for Emacs

If you use Emacs, you can use a AutoHotkey mode i wrote. It fixes some problems i found in the bundled ahk mode. Get it at Emacs: Xah AutoHotkey Mode .

Useful AutoHotkey Scripts

AutoHotkey Example Scripts

AutoHotkey Tutorial

AutoHotkey logo nz9fX