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 http://www.autohotkey.com/

Just run the installer to install it.

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
F9::
Send Best,{Enter}{Enter} Mary Jane
Return

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

Create a link to your script and put the link in $AppData\Microsoft\Windows\Start Menu\Programs\Startup

Hold down Alt and drag you AutoHotkey script file to the folder. This will create a link shortcut to your Startup folder.

Windows 10 start menu folder 2021-02-14
Windows 10 start menu folder 2021-02-14

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 AutoHotkey Mode (xahk-mode) .

Useful AutoHotkey Scripts

AutoHotkey Example Scripts .

If you have a question, put $5 at patreon and message me.

AutoHotkey Tutorial

AutoHotkey logo nz9fX