
π This article includes 1 downloadable practice file β
In this article
AutoHotkey (AHK) is a free, open-source scripting language for Windows that lets you automate repetitive tasks, create keyboard shortcuts, and build productivity tools with just a few lines of code. Used by millions of developers, gamers, and power users worldwide, AHK can save hours of daily repetitive work.
What is AutoHotkey?
AutoHotkey was created in 2003 by Chris Mallett and has grown into one of the most popular Windows automation tools, with over 1.4 million registered users on the official forum. It runs as a background process and listens for your defined triggers β hotkeys, hotstrings, or timed events.
Basic Level: Writing Your First AutoHotkey Script
An AHK script is a plain text file with the .ahk extension. Download AutoHotkey from autohotkey.com, install it, right-click anywhere on your desktop, and choose New β AutoHotkey Script.
; This is a comment. Lines starting with ; are ignored.
; Press Win+H to show a greeting message
#h::MsgBox Hello, World! AutoHotkey is working!
; Press Ctrl+Alt+N to open Notepad
^!n::Run Notepad
; Replace "btw" with "by the way" anywhere you type it
::btw::by the way
; Press F1 to type your email address instantly
F1::Send your.email@gmail.com
; Press Ctrl+Shift+C to copy formatted date to clipboard
^+c::
FormatTime, today,, dd-MMM-yyyy
Clipboard = %today%
MsgBox Copied: %today%
Return
Key symbols: # = Win key, ^ = Ctrl, ! = Alt, + = Shift. Double colon :: separates the trigger from the action.
Common Beginner Commands Reference
| Command | What It Does | Example |
|---|---|---|
Send | Types text or keystrokes | Send Hello{Enter} |
MsgBox | Shows a popup message | MsgBox Done! |
Run | Opens a program or file | Run chrome.exe |
Sleep | Waits (milliseconds) | Sleep 1000 |
WinActivate | Brings a window to front | WinActivate Excel |
InputBox | Gets user input | InputBox, name, Enter Name |
Clipboard | Read/write clipboard | Clipboard = "Hello" |
Intermediate Level: Variables, Loops and Windows Automation
; Variables and input boxes
InputBox, UserName, Enter Name, What is your name?
MsgBox Hello, %UserName%! Welcome to AHK.
; Loop: type numbers 1-10 into the active window
^!L::
Loop 10 {
Send %A_Index%{Enter}
}
Return
; Move and resize the active window to a fixed position
^!M::
WinMove, A,, 100, 100, 1200, 700
MsgBox Moved to 100,100 and resized to 1200x700
Return
; Clipboard automation: convert selected text to UPPERCASE
^!U::
Send ^c
Sleep 100
Clipboard := StrUpper(Clipboard)
Send ^v
Return
; Loop through files in a folder
^!F::
Loop, C:MyFolder*.txt
{
MsgBox % A_Index ": " A_LoopFileName
}
Return
Expert Level: GUI Applications and Advanced Automation
; Build a fully functional GUI application
^!G::
Gui, Add, Text, x10 y10 w200, Task Description:
Gui, Add, Edit, vTaskText x10 y30 w300 h80
Gui, Add, DropDownList, vPriority x10 y120 w150, High|Medium|Low
Gui, Add, Button, Default x10 y155 w100, Save Task
Gui, Add, Button, x120 y155 w100, Clear
Gui, Show, w330 h200, Quick Task Manager
Return
ButtonSaveTask:
Gui, Submit, NoHide
if (TaskText = "") {
MsgBox Please enter a task description!
Return
}
FileAppend, [%Priority%] %TaskText%`n, %A_Desktop% asks.txt
GuiControl,, TaskText,
MsgBox Task saved to your desktop!
Return
ButtonClear:
GuiControl,, TaskText,
Return
GuiClose:
Gui, Destroy
Return
AutoHotkey Real-World Use Cases
- Data entry automation: Fill forms with one keypress using stored templates
- Text expansion: Type
;addrto auto-expand to your full address - Window manager: Snap windows to precise positions with hotkeys
- Gaming macros: Automate repetitive in-game actions (where allowed)
- Excel helper: Launch macros, navigate ribbons, automate copy-paste workflows
Pro tip: Put #NoEnv and SetBatchLines -1 at the top of every script for best performance. Add ^!R::Reload during development to quickly restart after edits.
π Practice files for this article
- β¨οΈLesson 2 script (AutoHotkey v2)Double-click to run after installing AutoHotkey v2.β¬ AHK Β· 310 B
Free to use for learning. Files with macros (.bas) are plain text β import them with Alt+F11 β File β Import File, and always test on a copy.
Stuck on a step? Ask a question and the AI answers using this article.