AutoHotkey v2: Write Your First Time-Saving Script Today
Five short lines of AutoHotkey v2 fix CapsLock, type your email address for you and launch apps on your own shortcuts.
Count how often you type your email address in a week. Or "Best regards" plus your name. Or how often you hit CapsLock by accident and SHOUT HALF A SENTENCE. Each of those moments costs a few seconds. Together they add up, and they are boring.
AutoHotkey fixes that with tiny text files. You write one line, save, double-click, and Windows suddenly knows a new trick. Version 2 (currently 2.0.31) has a cleaner syntax than the old v1. This guide builds one small script with five useful lines. No programming background required.
Step 1: Install AutoHotkey and open the Dash
Download the v2 installer from the UpdateStar product page and click Install. When it is done, open the Start menu and click the AutoHotkey shortcut. That opens the Dash, a small launcher with these entries:
- New script creates a script from a template.
- Compile turns a script into a standalone .exe file.
- Help files (F1) opens the offline manual.
- Window Spy shows details about any window, handy later.
- Launch settings and Editor settings set how scripts run and which editor opens them.
The offline help is excellent and full of copy-ready examples. Press F1 in the Dash whenever you get stuck.
Step 2: Create your script file
Two roads lead to the same file:
- In the Dash, click New script, type a name such as MyTricks (without the .ahk extension) and click Edit. The file is created and opens in your editor.
- Or right-click an empty spot in a folder in File Explorer, choose New > AutoHotkey Script, name it and keep the .ahk ending.
If you go the Explorer route, right-click the new file and choose Edit Script. AutoHotkey asks for a default editor the first time. Notepad works fine. Visual Studio Code is nicer once you write longer scripts.
Make sure the first line of the file reads like this (the default template usually has it already):
#Requires AutoHotkey v2.0
Leave it there. It tells the launcher that this is a v2 script, so it never gets confused with old v1 code you may find online.
Step 3: Let abbreviations type for you
Hotstrings are the quickest win. Add this line below the first one:
::btw::by the way
Save the file and double-click it in Explorer. A green H icon appears in the notification area, which means your script is running. Now type btw in any text field and press Space. AutoHotkey erases the abbreviation and writes "by the way".
By default the replacement only fires after an ending character such as Space, Enter, a period or a comma. That protects you from accidental triggers inside longer words. If you want a hotstring to fire instantly, add an asterisk between the first two colons:
:*:@@::[email protected]
Replace the address with your own. The moment you type the second @, the full address appears. Pick abbreviations you never type by accident: @@ or ;sig are safer than plain words.
Step 4: Tame CapsLock
Few keys cause more accidental shouting. The AutoHotkey docs suggest this pair of lines, which turns CapsLock into a second Ctrl key and still lets you switch real caps on when you need it:
+CapsLock::CapsLock
CapsLock::Ctrl
Order matters here. The first line, with Shift+CapsLock, must come before the second. After saving, CapsLock behaves like Ctrl, so CapsLock+C copies. Hold Shift and press CapsLock to toggle capital letters the old way.
If you just want CapsLock gone completely, a single line does it:
CapsLock::return
Use one variant, not both, or the script will complain about a duplicate hotkey when you reload it.
Step 5: Launch apps with a shortcut of your own
A hotkey is a key combination followed by two colons. The symbols for modifiers are short: ^ is Ctrl, ! is Alt, + is Shift and # is the Windows key. This line opens Notepad with Ctrl+Alt+N:
^!n::
{
if WinExist("ahk_class Notepad")
WinActivate
else
Run "notepad"
}
The block is smarter than a plain launch: if a Notepad window is already open, it brings that window to the front instead of opening another one. The same pattern works for any program. Replace notepad with the full path of an .exe file in quotes. Run also opens folders and documents, for example Run A_MyDocuments opens your Documents folder.
Avoid stealing shortcuts that Windows already uses. Combinations with Ctrl+Alt are usually free.
Step 6: Ask before something drastic happens
Hotkeys can do things you might regret, like emptying the Recycle Bin. A message box adds a safety net:
^!Del::
{
if MsgBox("Would you like to continue?", "Warning", "YesNo") = "Yes"
FileRecycleEmpty
}
The message box created by MsgBox with the YesNo option.
Only a click on Yes empties the bin. No or closing the box does nothing. You can reuse this pattern for any hotkey that deletes, closes or sends something.
Step 7: Reload after every change
Scripts read their code once at start. Edits only count after a reload.
- Save the file in your editor.
- Right-click the green H icon in the notification area.
- Click Reload Script.
The same menu offers Edit Script, Suspend Hotkeys (handy during games), Pause Script and Exit. If you reload a lot, give yourself a hotkey for it:
^!r::Reload
When a reload fails, AutoHotkey shows an error message that points to the problem. Read it, fix the line, save and reload again. Typical culprits are a missing quote or a brace that never closes.
Step 8: Start the script with Windows
A script only works while it runs. To make it start after every login:
- Press Win+R, type shell:startup and press Enter. Your personal Startup folder opens.
- In a second Explorer window, right-click your .ahk file and drag it into the Startup folder.
- Choose Create shortcuts here when you release the mouse button.
Keep the original script where it is. The shortcut in Startup just points to it, so later edits apply automatically after the next reload.
Our verdict
AutoHotkey v2 is for anyone who types the same things over and over or wants a keyboard that works their way, and you do not need to be a programmer to profit from it. Start today with one hotstring for your email address and the CapsLock fix. Live with them for a week, and you will know exactly which shortcut to add next.
