|
AutoHotKey, focussing on migration from AHK1.1 to AHK2.0 category 'KB', language AHK2, created 16-Aug-2025, version V1.0, by Luc Pattyn with the assistance of Microsoft Copilot. |
|
License: The author hereby grants you a worldwide, non-exclusive license to use and redistribute the files and the source code in the article in any way you see fit, provided you keep the copyright notice in place; when code modifications are applied, the notice must reflect that. The author retains copyright to the article, you may not republish or otherwise make available the article, in whole or in part, without the prior written consent of the author. Disclaimer: This work is provided |
AutoHotkey (AHK) is a free, open-source scripting language for Windows that allows users to automate tasks, create custom keyboard shortcuts, and build lightweight utilities. It can be downloaded from https://www.autohotkey.com/.
AutoHotkey v2.0 marks a major evolution in the scripting language, bringing it closer to conventional programming standards. This article summarizes key differences from v1.1, offers practical migration advice, and shares personal insights from a recent conversion experience.
Hotkeys are now functions, with their code enclosed in curly braces (unless single-line).
Literal strings must use double quotes.
Commas and percent signs are gone — cleaner syntax overall.
Examples:
Send("{RButton Down}")
KeyWait("RButton")
activeClass := WinGetClass("A") ("A" means Active Window)
Think in terms of C, C#, or even VB.NET — with real variables, functions, and objects.
:= is for assignment, = is for comparison.
Arrays are now 1-based.
Manual conversion is entirely doable. Here's a recommended approach:
Replace all /* ... */ block comments with line comments.
Install AutoHotkey v2.0 — do not allow it to install v1.1.
Take your v1.1 script and wrap it in a giant comment block using /* at the top and */ at
the bottom.
Iteratively move the /* line downward, fixing issues as AHK v2.0 reports them.
This method avoids juggling two files and allows partial execution of converted code immediately.
Include #Warn in your header for better feedback.
Use static variables for local state — avoid global unless truly necessary.
Take advantage of AHK’s built-in Help system — it supports multiple windows for side-by-side reference.
#Requires AutoHotkey 2.0 ; Heavily relying on the improved syntax rules
#Warn ; Enable warnings to assist with script writing
;#NoTrayIcon ; Suppress tray icon for background utilities
#SingleInstance force ; Ensures only one instance of the script is running
SendMode "Input" ; Preferred for speed and reliability
SetTitleMatchMode(2) ; Allows partial window title matching
AutoHotkey v2.0 is a leap forward in clarity, consistency, and capability. While the transition requires effort, the payoff is a cleaner, more maintainable scripting environment. This article reflects my own journey — and I hope it helps others take the leap with confidence.
Perceler |
Copyright © 2012, Luc Pattyn |
Last Modified 03-Feb-2026 |