Updated July 2024 by Rose Echeguren
AutoHotKey is a free Windows scripting language program designed to streamline tasks using keyboard shortcuts. It allows users to create customized code (known as a “script”) to define their own keyboard shortcuts (like Ctrl + c to copy). With AutoHotKey, you can:
Create your own keyboard shortcuts or "hotkeys"
Automate repetitive tasks
Open web pages and manipulate windows
And more!
If you frequently use keyboard shortcuts, spend considerable time copying and pasting the same content, or regularly navigate to specific websites, AutoHotKey can save you a lot of time and energy in your daily work!
This guide focuses on 4 basic commands: Send, Run, Sleep and ExitApp. These commands are essential for automating keystrokes and launching applications. While these commands are fundamental, AutoHotKey offers a wide range of additional commands that can further enhance your automation scripts. Explore the "Helpful Resources" tab in this libguide to discover the full power of AutoHotKey.
The Send command is used to simulate keystrokes and mouse clicks. It allows you to automate typing and other keyboard actions.
Syntax: Send, xyz
Examples:
Typing Text:
^h::Send, Hello, World!
When you press "Ctrl + h," the text "Hello, World!" will be typed.
Sending Special Keys:
^c::Send, ^c
When you press "Ctrl + c," it simulates the "Copy" action, similar to the standard "Ctrl + C" shortcut.
The Run command is used to execute programs, open files, or navigate to specific URLs. It allows you to launch applications or open documents with a specified hotkey.
Syntax: Run, path or URL
Examples:
Opening Notepad:
^n::Run, Notepad
When you press "Ctrl + n,", the Notepad program will open.
Launching a web browser and navigating to a website
^w::Run, https://www.https://guides.uflib.ufl.edu/rds-uf.com
When you press "Ctrl + w," your default web browser will open the Resource Description Services libguide.
The Sleep command is essential for timing control in your scripts. It is used to pause the execution of a script for a specified duration. This can be useful for creating delays between actions or giving a program time to respond.
Syntax: Sleep, milliseconds
Examples:
The ExitApp command is used to terminate an AutoHotKey script. When this command is executed, the script stops running immediately. You can include this command independently at the end of the script or assign a hotkey to it to stop the script at any time.
Syntax: ExitApp
Examples:
Note: In AutoHotKey language, ^ represents the "Ctrl" key and :: is used to define hotkeys (kind of like an = sign).
Here's an example script that uses the Send, Run, Sleep and ExitApp commands:
Note: Text following a semicolon (;) is a comment. It does not perform any actions and is included only to make the script more readable for us humans.
; Define a hotkey to run the script
^r:: ; When Ctrl + r is pressed, the following actions will occur
; Open Notepad
Run, Notepad
; Wait for 2 seconds for Notepad to open
Sleep, 2000
; Send a text string to Notepad
Send, Hello, World!
; Wait for 1 second
Sleep, 1000
; Save the file (Ctrl + S)
Send, ^s
; Wait for the Save dialog to appear
Sleep, 1000
; Type the filename
Send, MyNote.txt
; Press Enter to save
Send, {Enter}
; Exit the script
ExitApp
In this example, I've written a script that creates a hotkey (Ctrl+r) that opens Notepad, types "Hello, World!" into the Notepad window, saves the file as "MyNote.txt" using the Ctrl + S shortcut, and then closes Notepad. Now your turn!