AutoHotkey Tutorial ⌨

, , …,
AutoHotkey logo

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

For example, you can:

Download AutoHotkey

Download at

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.

Quitting AutoHotkey

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.

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

AutoHotkey Example 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

AutoHotkey Key Notation

Complete syntax for keys and mouse: 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
Send Best,{Enter}{Enter} Mary Jane

In the above, the {Enter} means the Enter ↵ key. When you press F8, then it'll type:


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

blog comments powered by Disqus