This page provides a complete overview of changes between AutoHotkey v2.0 and v2.1. For changes made after v2.1, see the changelog. For full technical details of changes, refer to GitHub.
Note: This page describes AutoHotkey v2.1. Follow the links to the current API pages for Keysharp behavior and see Keysharp differences and limitations.
These changes may prevent v2.0 scripts from working as expected in the current release.
The Tray menu and Menu.Show now use modeless menus to allow new threads to launch without freezing the menu. OS support for modeless menus has some bugs relating to Z-order and ability to click the first item in a submenu. Modeless menus are currently enabled by default, but this may be changed if workarounds are not found for these bugs.
DPI awareness now defaults to per-monitor v2 instead of system.
This change should affect scripts only in the scenarios described under OS DPI Scaling. Understanding the implications of the change requires a general understanding of DPI Scaling and more specifically two phenomena which affect system DPI aware scripts when there is a DPI mismatch:
Per-monitor DPI awareness disables DPI virtualization and bitmap-scaling, and therefore requires the program to react to DPI changes, such as by resizing the GUI and its controls. This is now done automatically by default unless the script disables DPIResize for the GUI or control. The built-in scaling is not expected to be perfect, and will require additional help from the script in some cases.
Scripts which do not work well with the new default can restore the previous mode within a more limited context, as described in DPI Scaling - Mixed Settings.
Scripts which were designed to opt in to per-monitor mode should be relatively unaffected by this change. Such scripts might have previously observed the mode unexpectedly reverting under specific conditions, because the script's main window is created before the script sets the mode. See DPI Scaling - New Threads for details.
Hard-coded screen coordinates and offsets for secondary screens may need to be adjusted, but that would already be the case if display settings were changed.
Some changes to the script's behavior are enabled only if #Requires is used to specify a version requirement which cannot be met by "2.0.x". There are currently two modes: v2.0 mode and v2.1 mode. The mode can be set independently for each module and function. For details of how the directive is applied, see Compatibility Mode (#Requires).
v2.0 mode is used by default, but does not prohibit the use of features which require v2.1.
This term is used with property and return values. For v2.0 and when returned to a caller in v2.0 mode, the value is "" (an empty string). If an arrow function performs a tail call such as X() => Y(), a blank-unset result can be propagated without the maybe (?) operator. Otherwise, it is equivalent to unset.
Built-in functions return blank-unset if they lack a documented return value.
These return blank-unset under specific conditions where "" was previously returned:
When the end of a function body is reached or return is used without a parameter, the function may return "" (an empty string), unset or blank-unset.
"".unset if return is used with a parameter elsewhere within the function.If a function or property called from v2.0 mode returns blank-unset, it is translated to "" (an empty string).
See also: Default Return, blank-unset
[v2.1-alpha.35+]: #Include <A_B> checks for "A_B" before "A_B.ks" and "A_B.ahk", and does not check for "A.ahk". Refer to Script Library Folders for details.
[v2.1-alpha.35+]: AutoHotkey's Map rejects Float keys with TypeError; Keysharp's Map continues to accept them. Array rejects Float and nonnumeric indices with TypeError, including float numeric strings; integer strings remain accepted. The array checks apply to __Item, Get, Has, Delete, InsertAt and RemoveAt.
These return unset under specific conditions instead of throwing an error:
Overall, unset is returned more consistently when an item or value is absent, whereas in v2.0 (and v2.0 mode) some methods return "" and some methods or properties throw UnsetItemError.
See also: Default Return, blank-unset
These changes should not prevent v2.0 scripts from working, but may affect the behavior of the program. This includes some changes to behavior which was previously undocumented (and therefore not something a script should have relied on), and some changes to documented behavior which should generally not require changes to existing scripts.
InputHook: Removing an option from an SC-based key by name with KeyOpt now also removes the option from the corresponding VK (the reverse was already true).
ListVars now shows unset vars as "varname: unset" instead of showing string length and capacity.
MouseGetPos now throws OSError if the mouse position cannot be determined.
RegExReplace no longer truncates Replacement at the first null character (if any).
Showing the tray menu no longer stalls the current thread.
#Warn with no parameters now turns on VarUnset and Unreachable and turns off LocalSameAsGlobal for the current module, instead of enabling all warnings and setting to MsgBox mode (like #Warn All, MsgBox).
Added a warning for UTF-8 decoding errors in script files.
WinTitle parameters with two different ahk_id values now yield no match instead of arbitrarily ignoring one of the two values.
The manifest embedded in each EXE now has disableWindowFiltering, allowing more windows to be detected.
The following now use ASCII-only case insensitivity instead of locale case insensitivity: Tab control's UseTab method (excluding FullNameMatch mode, which was already ASCII-only), Choose method and Text property; Menu's Add method.
Property setters defined in a class now allow the value parameter to be omitted (unset) so that assignments like x.y := unset can be handled. Setters which aren't designed to account for this may start executing the setter and throw UnsetError when value is evaluated, instead of throwing an Error immediately when the setter is called.
Some functions which previously always returned "" (without that being documented) now return a more useful value:
HotIf now returns the previous value of A_HotIf.
The ToggleCheck and ToggleEnable methods of Menu now return the new state.
Text input collection and dead key handling have been changed:
InputHook now handles {dead key}{BS} so that BS cancels out dead key.
Remapping now utilizes left/right modifiers in Blind; e.g. >^a::b remaps RCtrl-A to B and LCtrl-RCtrl-A to LCtrl-B, instead of just B.
Ctrl::Alt no longer sends an unsuppressed {Ctrl up}. This was originally intended to work around an issue with system handling of the modifier keys, but was superseded by a better workaround in v2.0.8.
DBGp property and context commands have been improved:
DBGp now defaults to max_children = 1000 and max_depth = 1.
Debugger now lists properties defined by the Prototype for non-Object classes such as VarRef and ComValue, instead of a hard-coded (possibly empty) set of pseudo-properties.
Debugger classname attribute of Prototype objects now includes the class name (e.g. "SomeClass.Prototype").
Debugger no longer lists the natively-defined __Class or Base properties.
Global, local and static variable declarations with multiple initializers are now evaluated as a single expression, so there is no need to step over each initializer individually while debugging.
Basic support for per-monitor DPI awareness is now available, including:
For details, see DPIResize (Gui).
These additions should generally not affect v2.0 scripts at all.
Modules, #Module, and #Import are now available.
Function definition expressions are now supported.
The operator a !~= b is now available, which is equivalent to !(a ~= b) (shorthand for "not RegExMatch").
Typed properties (structures) are now supported.
Functions and properties can now return unset, and the maybe (?) and or-maybe (??) operators can allow or handle it.
Mandatory parameters can now be defined to the right of optional parameters, such as Fn(a?, b).
Optional chaining with the maybe operator (a?.b) is now supported.
The maybe-assign operator (??=) is now available.
Load-time validation for unset, ? and ?? has been improved.
A length limitation for parameter default strings (but not expressions) has been removed.
Any.Prototype.Props() and Props are now available to enumerate own and inherited properties.
Virtual references are now supported:
&x.y invokes x.__ref('y').Class.Call now accepts additional optional parameters to facilitate creating classes dynamically. In particular, this enables scripts to dynamically create Prototype objects which are based on native types other than Object, such as Map and Array.
{Blind} now supports left/right modifiers, as in {Blind>^}.
Remapping now supports WheelUp, WheelDown, WheelLeft and WheelRight on either side.
Auto-replace hotstrings now avoids retyping an identical leading part, where feasible.
InputHook now supports the H option for intercepting hotkeys.
ATan2: New function.
CallbackCreate: An array of parameter types can now be specified instead of a parameter count.
DllCall: CDecl can now be omitted regardless of which calling convention the function uses.
Edit: Added an optional Filename parameter.
FileCreateShortcut: The ShortcutKey parameter now permits the ^, + and ! modifiers.
ImageSearch: X and Y can now be omitted.
IsSet: Now accepts any unset expression. For example: IsSet(X?.Y)
PixelSearch: X and Y can now be omitted.
ProcessWait: ListLines now shows "STILL WAITING" if it was interrupted and resumed waiting, as it already did for WinWait.
RegExReplace: Replacement can now be a callback function instead of replacement text.
Throw: Now a function, for greater flexibility.
TraySetIcon: Now updates the icon of the script's main window.
Type: Now returns the string "unset" if Value is unset. For example: Type(MyVar?)
WinGetAlwaysOnTop: New function.
WinGetEnabled: New function.
A_KeybdHookInstalled and A_MouseHookInstalled are now available.
A_HotIf is now available.
Gui:
Menu:
ahk_class is now case-insensitive when not using the RegEx mode.
These optimizations improve performance but otherwise do not affect behavior.
Pause now allows the OS-level thread to sleep until messages are received, instead of polling the pause state frequently. In testing, this reduced CPU usage from 0.04% to 0.00%.
ProcessWaitClose and RunWait now allow the OS-level thread to sleep until the process handle is signaled or messages are received. This reduced CPU usage (as above) and improved the response time.
Dialog window class check optimizations.
The ternary operator no longer performs a redundant numericness check.
Window search optimizations; see WinTitle - Performance for details.