Skip to content

AutoHotkey v2 Tutorial for Windows: Shortcuts, Hotstrings and Scripts

AutoHotkey is a Windows scripting tool for creating custom keyboard shortcuts, correcting frequent typos, launching programs, and automating repetitive input. This guide demonstrates AutoHotkey v2, which uses different syntax from the older v1 examples on this site. For simple tasks, Windows already provides keyboard shortcuts; use a custom script only when it adds clear value.

What can AutoHotkey automate?

  • App launch shortcuts: open Notepad or another application with keys you choose.
  • Hotstrings: expand abbreviations or correct repeated misspellings as you type.
  • Keyboard remapping: reassign selected keys for a specific workflow or accessibility need.
  • Repeated text entry: insert boilerplate phrases in approved applications.
  • Window management: automate allowed actions in desktop applications, with care around screen focus and permissions.

AutoHotkey does not work identically in every app. Security-sensitive fields, games, remote desktops and applications using elevated permissions can handle simulated input differently. Never run a script from an untrusted source or put secrets and passwords inside plain-text macros.

First check built-in Windows shortcuts

Windows + E opens File Explorer; Windows + Shift + S launches screen capture; Alt + Tab switches applications; and Windows + V opens supported clipboard history. You do not need AutoHotkey to use these features. For a guide on historical and current clipboard methods, see multiple clipboards in Windows.

Install AutoHotkey v2 and create a script

  1. Get AutoHotkey from its official website. Select a maintained v2 release and follow your organization’s software policy.
  2. Create a plain-text file named MyShortcuts.ahk. Check that its extension is .ahk, not .aht or .txt.
  3. Paste the v2 sample below and save the file.
  4. Open the file with the AutoHotkey v2 interpreter. Test shortcuts in Notepad before adding more complicated actions.

AutoHotkey v2 example: Open an app and expand text

#Requires AutoHotkey v2.0
#SingleInstance Force

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

; A hotstring expands after typing a word-ending character.
::btw::by the way

; Ctrl+Alt+Q types a pre-written message.
^!q::SendText("Thank you for your message.")

Here ^ means Ctrl, ! means Alt, and ^!n means Ctrl + Alt + N. The Run("notepad.exe") call opens Notepad. The ::btw:: hotstring expands btw into “by the way” when a normal ending key is typed. SendText() inserts a literal phrase, and should be used only in fields where simulated text entry is appropriate.

For updated syntax, consult the official AutoHotkey v2 documentation. A script using old command syntax such as Run, notepad or Clipboard := ClipboardAll cannot simply be pasted into a v2 script without checking compatibility.

Run, stop and troubleshoot a script

  1. Start the .ahk script and look for its AutoHotkey icon in the notification area.
  2. Try Ctrl + Alt + N in an ordinary desktop session, then try the text expansion in Notepad.
  3. If a shortcut conflicts with another application or keyboard layout, change its combination. In some layouts, Ctrl + Alt may overlap with AltGr input.
  4. To stop the script, right-click its tray icon and choose Exit. Use the script editor to make changes and restart or reload as needed.

Script not loading? Verify the interpreter version first. Shortcut not firing? Check keyboard conflicts, focus, application permissions and whether the script is still running. Hotstring does not expand? Test it in a basic text editor and type a delimiter after the abbreviation.

Original AutoHotkey demonstration video

This demonstration is retained from the original article. It uses older AutoHotkey syntax and may show shortcuts or Windows features that have changed. Use the version 2 code above for a new installation.

Legacy AutoHotkey v1 examples — historical appendix

The original article included several scripts for launching software, abbreviations, searches, key remapping and switching windows. They are retained below as a legacy reference, not as recommended modern code. In particular, examples that place selected text into an external search URL could disclose private information and may require proper URL encoding and clipboard safeguards. Do not run these on confidential content.

Original example 1 (AutoHotkey v1 syntax, not for v2): Retained for readers who need to recognize or migrate older scripts. Do not execute blindly; commands may need updates, and some examples copy clipboard text or send it to public websites.

#n:: 
run notepad
return

Original example 2 (AutoHotkey v1 syntax, not for v2): Retained for readers who need to recognize or migrate older scripts. Do not execute blindly; commands may need updates, and some examples copy clipboard text or send it to public websites.

#n::
run notepad++
return

Original example 3 (AutoHotkey v1 syntax, not for v2): Retained for readers who need to recognize or migrate older scripts. Do not execute blindly; commands may need updates, and some examples copy clipboard text or send it to public websites.

:*:teh::the
:*:enviorment::environment
:*:knwo::know

Original example 4 (AutoHotkey v1 syntax, not for v2): Retained for readers who need to recognize or migrate older scripts. Do not execute blindly; commands may need updates, and some examples copy clipboard text or send it to public websites.

::hbd:: Happy Birthday !!!

Original example 5 (AutoHotkey v1 syntax, not for v2): Retained for readers who need to recognize or migrate older scripts. Do not execute blindly; commands may need updates, and some examples copy clipboard text or send it to public websites.

#g::
OldClipboard:= Clipboard
Clipboard:= ""
Send, ^c ;copies selected text
ClipWait
Run http://www.google.com/search?q=%Clipboard%
Sleep 200
Clipboard:= OldClipboard
Return

#w::
OldClipboard:= Clipboard
Clipboard:= ""
Send, ^c ;copies selected text
ClipWait
Run http://en.wikipedia.org/wiki/Special:Search?search=%clipboard%
Sleep 200
Clipboard:= OldClipboard
Return

Original example 6 (AutoHotkey v1 syntax, not for v2): Retained for readers who need to recognize or migrate older scripts. Do not execute blindly; commands may need updates, and some examples copy clipboard text or send it to public websites.

Numlock::Shift
Return

Original example 7 (AutoHotkey v1 syntax, not for v2): Retained for readers who need to recognize or migrate older scripts. Do not execute blindly; commands may need updates, and some examples copy clipboard text or send it to public websites.

Insert::
OldClipboard:= Clipboard
Clipboard:= ""
Send, ^c ;copies selected text
ClipWait
Run http://en.wikipedia.org/wiki/Special:Search?search=%clipboard%
Sleep 200
Clipboard:= OldClipboard
Return

Original example 8 (AutoHotkey v1 syntax, not for v2): Retained for readers who need to recognize or migrate older scripts. Do not execute blindly; commands may need updates, and some examples copy clipboard text or send it to public websites.

ToggleWinMinimize(TheWindowTitle)
{
SetTitleMatchMode,2
DetectHiddenWindows, Off
IfWinActive, %TheWindowTitle%
{
WinMinimize, %TheWindowTitle%
}
Else
{
IfWinExist, %TheWindowTitle%
{
WinGet, winid, ID, %TheWindowTitle%
DllCall("SwitchToThisWindow", "UInt", winid, "UInt", 1)
}
}
Return
}
!c::ToggleWinMinimize("Chrome")

Original resource links

  • Original reference 1 — historical link retained from the original article; availability and compatibility may have changed.
  • Original reference 2 — historical link retained from the original article; availability and compatibility may have changed.
  • Original reference 3 — historical link retained from the original article; availability and compatibility may have changed.
  • Original reference 4 — historical link retained from the original article; availability and compatibility may have changed.
  • Original reference 5 — historical link retained from the original article; availability and compatibility may have changed.

Should you use AutoHotkey or a built-in shortcut?

Prefer built-in Windows functionality when it already solves the task. Use AutoHotkey for narrowly defined custom shortcuts and keep each script small, readable and easy to disable. If you are learning from historical videos or scripts, confirm the AutoHotkey version before applying an example.

2 thoughts on “AutoHotkey v2 Tutorial for Windows: Shortcuts, Hotstrings and Scripts”

  1. Pingback: Remapping Keys in Windows using PowerToys for free [2024]

  2. Pingback: Multiple Clipboard in Windows with AutoHotkey(freeware). - PickupBrain: Be Smart

Leave a Reply

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