|
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.
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.Manual conversion is entirely doable. Here's a recommended approach:
/* ... */ block comments with line comments./* at the top and */ at the bottom./* line downward, fixing issues as AHK v2.0 reports them.This method avoids juggling two files and allows partial execution of converted code immediately.
#Warn in your header for better feedback.static variables for local state — avoid global unless truly necessary.#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 21-May-2025 |