AutoHotkey Tutorial

AutoHotkey is a keyboard macro software for Microsoft Windows. It is free.
For example, you can:
- Define F8 to launch browser, and just switch to it if it is already running.
- Set F3 to Copy, F4 to Paste.
- Define F12 to close a browser tab.
- Swap Alt and Ctrl keys, or disable CapsLock, NumLock, or make ScrollLock keys do something useful.
- Define abbreviations, so pressing a key automatically inserts today's date.
Download AutoHotkey
Download at http://www.autohotkey.com/
Just run the installer to install it.
Create Script, Run Script
To create a AHK script, for example, save the following text into a file, and name it test.ahk
:
; launch Notepad Run Notepad
AutoHotkey language is not case sensitive. Run
is the same as run
.
To run the script, just double click it. It will launch Notepad, then the script will exit.
Here's how you create a keyboard shortcut for launching Notepad:
; make Win+n as a hotkey for launching Notepad #n::Run Notepad
Save the above in a file. Then, double click on it. Then, pressing ❖ Window+n will launch Notepad.
Quitting AutoHotkey

Once you run the above script, it stays running as a background process. You can see it in your Taskbar's notification area.
Right click on the AutoHotkey icon and pull a menu to quit the script. If you quit, your hotkeys will not work anymore.
Launch Apps, Open File, URL
Here's examples of launch application, open file, open URL.
; launch app by name Run Notepad ; launch app by path Run "C:\Program Files (x86)\Internet Explorer\iexplore.exe" ; open a file Run "%HOMEPATH%\Documents\todo.txt" ; open folder Run "%HOMEPATH%\Documents" ; open URL in default browser Run www.google.com
; launching a app with a parameter Run "C:\Program Files (x86)\emacs-23.1-bin-i386\emacs-23.1\bin\emacs.exe" "-Q"
Useful AutoHotkey Scripts
Assign a Key to Launch a App
; 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
Sending Text and Keystrokes
You can define a hotkey, so that, when pressed, it sends some other typing or keystrokes.
; pressing F8 to insert your signature F8:: Send Best,{Enter}{Enter} Mary Jane Return
In the above, the {Enter}
means the Enter key. When you press F8, then it'll type:
Best, Mary Jane
Note that AutoHotkey does not support Unicode well as of , even with the “AutoHotkey_L” version. That means, if the text you want to insert is Chinese, or is special characters such as → α, it won't work.
Start AutoHotkey when Windows Starts
You can make Windows automatically start your script when system starts.
Suppose your script is named MyHotkeys.ahk
. Open the folder
C:\Users\mary\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
Now, hold down Alt and drag your MyHotkeys.ahk
file to the folder. This will create a link shortcut to your Startup folder. When Windows starts, your script will also automatically 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 AutoHotkey Mode (xahk-mode) .
If you have a question, put $5 at patreon and message me.