AutoHotkey Tutorial ⌨

, , …,

This page is a basic tutorial on using AutoHotkey.

AutoHotkey is a keyboard macro software for Microsoft Windows. It is free.

For example:

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 【❖ 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"

Simple Useful AutoHotkey Examples

AutoHotkey Example Scripts.

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

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.

Start AutoHotkey when Windows 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