Skip to Main Content

AutoHotKey: Home

Updated July 2024 by Rose Echeguren

AutoHotKey

What is AutoHotKey?

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!

Download and Install AutoHotKey

  1. Go to https://www.autohotkey.com/
  2. Click on the "Download" button and follow the installation instructions.

Write a Basic Script

  1. Open the AutoHotKey Dash.
  2. Click "New Script," name the file (using the .ahk extension), and then click "Create."
  3. Right-click on the newly created script file and select "Edit Script." This will open the script in a text editor like Notepad.
  4. Create your script using the information provided in this libguide, the AutoHotKey Beginner Tutorial, and AI tools like ChatGPT as your guide.
  5. Once you've written your script, save the file and close the text editor.

Run and Test Your Script

  1. To run your script, double-click the script file or right-click on it and select "Run Script."
  2. Make sure your script performs as expected. If it works, great! If not, troubleshooting is part of the process. 

This guide focuses on 4 basic commands: SendRun, 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.

 

Send Command

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.

 

Run Command

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.

 

Sleep Command

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:

  • Sleep, 2000
  • This example pauses the script for 2000 milliseconds (2 seconds).

 

ExitApp Command

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:

  • ^q::ExitApp
  • In this example, pressing "Ctrl + q" will stop the script.

 

 

Note: In AutoHotKey language, represents the "Ctrl" key and :: is used to define hotkeys (kind of like an = sign).

Now for an Example!

 

Here's an example script that uses the Send, RunSleep 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!

Bilingual Metadata Specialist

University of Florida Home Page

This page uses Google Analytics - (Google Privacy Policy)

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.