Xah Lee, 2009-08-25, 2009-12-21, 2011-01-01
This page is a very basic tutorial on using AutoHotkey.
AutoHotkey is a keyboard macro software for Microsoft Windows. It is free and Open Source. It lets you assign any keyboard shortcuts to launch programs, type text or keys, or even mouse clicks. It has a basic scripting language.
For example, you can define F8 to launch browser, and just switch to it if it is already running. You can also use it to define abbreviations, so pressing a key automatically types today's date or other keyboard shortcuts. You can also define single keys to maximize window, or close window. You can also use it to swap Alt and Ctrl keys, or disable Caps Lock, Num Lock, or make ScrLk keys do something useful.
First, you need to download and install it, here: http://www.autohotkey.com/download/. Just run the installer to install it. AutoHotkey runs on my machine without any problem. My machine is 64 bits Windows Vista.
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 【Win+n】 will launch Notepad.
A running AutoHotkey script icon in Taskbar's System Notification Area.
Once you run the above script, it actually stays running as a background process. You can see it in your Taskbar's notification area. You can right click on the icon and pull a menu to exit the script. As long as the script is running, your hotkey is available to you.
Some examples of launching applications, opening files, url.
; you can use “Run” to launch apps or url Run Notepad ; launch a app by name Run "C:\Program Files (x86)\Internet Explorer\iexplore.exe" ; launch a app by path Run "%HOMEPATH%\Documents\todo.txt" ; launch a file Run "%HOMEPATH%\Documents" ; launch a folder Run www.google.com ; launch a url in default browser
; launching a app with a parameter Run "C:\Program Files (x86)\emacs-23.1-bin-i386\emacs-23.1\bin\emacs.exe" "-Q"
; assign a hotkey to launch a app #n::Run Notepad ; this means the Win+n !n::Run Notepad ; this means Alt+n ^n::Run Notepad ; this means Ctrl+n F6::Run Notepad ; F6 ^F6::Run Notepad ; Ctrl+F6 ^!n::Run Notepad ; Ctrl+Alt+n
The above should be all you need. If you need to define keys such as Home, End, PageUp, ScrLk, numberpad keys… and special keys such as Browser Back, Browser Forward, Play/Pause …, see: AutoHotkey Key Notations.
You can define a hotkey, so that, when pressed, it sends some other typing or keystrokes.
; pressing Ctrl+Alt+s 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 2011-01, 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.
For about 20 simple and useful scripts, see: AutoHotkey Example Scripts.
When you have a lot of hotkeys defined, everytime you restart your computer, you have to start your ahk script, otherwise the hotkeys won't be available. You can make Windows automatically start your script when system starts. Here's how.
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 creat a link shortcut to your Startup folder. When Windows starts, your script will also automatically start.
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).