Skip to content

AutoHotkey v2 Tutorial: Custom Windows Shortcuts and Text Expansion

Automate boring task in Windows

Want to open an application with a custom shortcut, expand frequently typed phrases, or automate repetitive keystrokes on Windows? AutoHotkey lets you write small scripts for these jobs. This introduction uses AutoHotkey v2 and separates tasks Windows already performs—such as clipboard history and screenshots—from actions that benefit from custom automation.

What is AutoHotkey?

AutoHotkey is a Windows scripting and automation tool for defining hotkeys (keyboard shortcuts), hotstrings (text replacements), and more complex actions. The syntax changed substantially from AutoHotkey v1 to v2. Many older tutorials and videos use v1, so check the version before copying scripts.

When you do not need AutoHotkey

  • Clipboard history: press Windows + V to view and paste previously copied items after enabling the feature. See our clipboard-history and custom slots guide.
  • Screen snippets: press Windows + Shift + S to capture a selected area with the Snipping Tool.
  • Common navigation: Windows + E opens File Explorer, Alt + Tab switches apps, and Windows + D shows the desktop.

Using built-in Windows features is easier when they already meet your needs. AutoHotkey is useful when you want a custom action that has no suitable built-in shortcut.

Step 1: Install AutoHotkey v2

  1. Visit autohotkey.com and choose the current v2 release.
  2. Follow the installer steps permitted on your Windows computer. On an organization-managed device, check its software policy first.
  3. Create a new plain-text file named MyShortcuts.ahk. Make sure the extension is .ahk, not .txt or .aht.
  4. Open the file in a text editor and paste the sample script below.

Step 2: Try three basic shortcuts

#Requires AutoHotkey v2.0
#SingleInstance Force

; Ctrl+Alt+N opens Notepad.
^!n::Run("notepad.exe")

; Typing "btw" followed by a word-ending key expands the text.
::btw::by the way

; Ctrl+Alt+Q inserts a short reusable phrase.
^!q::SendText("Thank you for your message.")

The first shortcut opens Notepad when you press Ctrl + Alt + N. The second changes btw into “by the way” after you type a normal word-ending character. The third inserts a reusable phrase when you press Ctrl + Alt + Q. These are intentionally simple AutoHotkey v2 examples; they are not compatible with the older v1 syntax without adaptation.

Step 3: Run, test and stop the script

  1. Save the .ahk file, then double-click it to start the script with the v2 interpreter.
  2. Open Notepad and test the text expansion and phrase shortcut. Try the app-launch hotkey, too.
  3. If a shortcut conflicts with your keyboard layout or another application, choose a different key combination.
  4. To stop the script, locate its AutoHotkey tray icon in the notification area, right-click it, and choose Exit.

A script can automate keyboard input in whichever app currently has focus. Always test on non-sensitive material and review the code; do not run untrusted scripts or weaken endpoint security protections to make a script work. Hotstrings do not reliably work in every game, remote desktop, or protected input field.

Original video: More AutoHotkey shortcut ideas

Top Windows hacks that will blow your mind: Automate any tasks in Windows using Autohotkey

The original video includes opening apps, correcting typos, text expansion, searching selected text, and other workflow ideas. It was recorded for an older AutoHotkey version. Use the v2 code in this article as your starter example rather than assuming historical video syntax will run in a current installation.

Other useful automation ideas

  • Text expansion: create abbreviations for standard replies, signatures, or frequently written technical phrases. Avoid inserting private credentials with plain-text automation.
  • Application shortcuts: launch frequently used tools with a memorable unused combination.
  • Keyboard remapping: customize a rarely used key, with care not to disable essential accessibility or security shortcuts.
  • Repeated form entry: automate permitted repetitive text entry, but confirm the correct window has focus before sending keystrokes.
  • Clipboard enhancements: use Windows + V for basic history and version-appropriate scripts only when fixed slots or specialized actions are needed.

Original video: Multiple clipboards

Copy Paste Multiple items at once in Windows using Autohotkey

The video demonstrates an older custom clipboard approach. Windows 10 and Windows 11 now include built-in clipboard history, so third-party scripting is optional for ordinary copy-and-paste history.

Legacy video chapters and references

The following references were retained from the original tutorial for readers who want to revisit its historical demonstrations. The hotkeys in those recordings may conflict with current Windows functions or require AutoHotkey v1.

Troubleshooting

  • The script does not run: confirm it is saved as .ahk and opened with AutoHotkey v2.
  • Error messages mention invalid syntax: you may be mixing v1 scripts with the v2 interpreter. Look for a matching version of the guide.
  • A hotkey does nothing: check for conflicts with Windows, an application, or AltGr on your keyboard layout.
  • Text expansion does not appear: some fields block simulated input; try the example in Notepad first.
  • Clipboard history is empty: open Windows + V and enable it under Settings > System > Clipboard.

Make a shortcut work only in one app

Global hotkeys can interfere with shortcuts in other applications. AutoHotkey v2 supports context-sensitive hotkeys using #HotIf. The example below enables Ctrl + Alt + J only while Notepad is the active window. It uses the Windows executable name rather than relying on the window title, which can change with the document.

#Requires AutoHotkey v2.0
#SingleInstance Force

#HotIf WinActive("ahk_exe notepad.exe")
^!j::SendText("Reviewed in Notepad.")
#HotIf  ; Restore global hotkey context for subsequent definitions.

Run this as a separate practice script or merge it carefully with your existing definitions. Test in Notepad first, then switch to another app and confirm the hotkey does not insert text there. If your Notepad installation uses a different process name, inspect the actual active window with AutoHotkey Window Spy rather than guessing.

Frequently asked questions

Does AutoHotkey run on macOS or Linux? AutoHotkey is designed for Windows; scripts in this guide are not cross-platform. Does a hotstring expand immediately? By default, a normal ending character such as a space or punctuation triggers the replacement. Can I use shortcuts in elevated apps? A normal-permission script may not send input to an elevated window. Do not elevate scripts unnecessarily; follow your organization’s security policy. How do I apply edits? Save the .ahk file and reload the running script from its tray menu, or exit and launch it again.

Summary

Use built-in Windows shortcuts when possible, then use AutoHotkey v2 for custom repetitive tasks. Start with a small script that you can read and test before adding complexity. Our Windows clipboard tutorial explains the difference between the older AutoHotkey v1 scripts and newer v2 approaches.

1 thought on “AutoHotkey v2 Tutorial: Custom Windows Shortcuts and Text Expansion”

Leave a Reply

Your email address will not be published. Required fields are marked *