AutoHotkey Tutorial ⌨

, , …,

This page is a basic tutorial on using AutoHotkey.

AutoHotkey is a keyboard macro software for Microsoft Windows. It is free. 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, set F1 F2 as Copy & Paste. 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.

Download AutoHotkey

First, you need to download and install it, here: http://www.autohotkey.com/. Just run the installer to install it. AutoHotkey runs on my Windows 7 and Windows Vista without any problem.

Create a Script; Run a 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 【❖ Win+n】 will launch Notepad.

AutoHotkey System Notification Area
A running AutoHotkey script icon in Taskbar's System Notification Area.

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.

Examples Syntax for Launch Apps or Open File

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 Key to Launch a App

; 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.

AutoHotkey Key Notation Reference

For syntax of all keys and mouse buttons/wheel, see: AutoHotkey 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 (⁖ {→ α}), it won't work.

Simple Useful AutoHotkey Examples

AutoHotkey Example Scripts.

Start AutoHotkey when Computer Starts

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 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).

blog comments powered by Disqus