AutoHotkey v2
AutoHotkey v2 aims to improve the usability and convenience of the language and command set by sacrificing backward compatibility. It has not yet reached a stable release - more compatibility-breaking changes will be made.
Downloads
Downloads, other links and more information.
Obsolete content below; refer to v2-changes.htm instead:
Overview of the first alpha release:
This alpha release contains most of the largest changes. Some of these changes are according to the plan, some are experimental, and a few I consider essential even though they weren't part of the plan. I don't plan to release an ANSI version, so a few of the points below are described with only the Unicode version in mind. I will outline the changes that have been made first, then the changes yet to be made.
Changes according to the plan:Changes based on the plan, but not precisely:
- IF accepts an expression by default, even if parentheses aren't used. The traditional modes of If Var = Value, If Var <> Value, If Var > Value, etc. have been removed.
- X = Y is no longer a literal assignment.
- X `= Y is a literal assignment, for now. This form was suggested by Laszlo. [v2.0-a004-abad6fe: Removed literal assignment.]
- #AllowSameLineComments, #MaxMem, SoundGetWaveVolume and SoundSetWaveVolume have been removed.
- #NoEnv is now the mandatory default behaviour, so the directive has been removed.
- All of the commands listed in the "Eliminate legacy commands that already have a modern counterpart" section of the plan have been eliminated. Note that the L#|R# functionality of StringGetPos (mentioned by Titan) was added to InStr back in Revision 57.
- #Delimiter has been removed. (In alpha 5, #CommentFlag, #DerefChar and #EscapeChar were also removed.)
- AutoTrim and A_AutoTrim have been removed. Trim(), LTrim() and RTrim() were added back in Revision 31.
- DriveSpaceFree has become DriveGet, OutputVar, SpaceFree, Drive.
- Blanks in math operations should be consistently treated as errors. So now x += 1, y -= 1 should behave the same whether the two assignments are written on separate lines or on a single line.
- PixelSearch and PixelGetColor now use RGB instead of BGR by default. (No option is provided to use BGR.)
- A_TitleMatchMode now defaults to 2 rather than 1.
Some legacy rules and restrictions have been removed, keeping with the theme of v2:
- SetFormat, A_FormatInteger and A_FormatFloat have been removed. All number to string conversions use the same format as the v1 default.
- The Transform command has been eliminated and the Deref sub-command has been promoted to a top-level command (Deref var, value).
- Characters made illegal in variable names: #, @ and $. Note that [, ] and ? were outlawed when objects were introduced in Revision 31. Additionally, variable names can no longer begin with numbers.
- Command-line args, if present, are turned into an object/array and assigned to the Args global variable.
Additional changes:
- Removed the special rule that = (equals) after , (comma) is assignment. For example, in x:=1, y=2 the second part will always be a comparison, not an assignment.
- Removed legacy exception for %var% in expression args. For example, return %var% is now equivalent to return (%var%) instead of return var.
- Numeric literals using scientific notation no longer require a decimal point. For example, 1e3 is equivalent to 1.0e3. I originally hoped to make 1e3 equivalent to 1000 (i.e. an integer), but it seemed difficult to do without sacrificing performance and simplicity.
There was some discussion about changing the syntax for var derefs from %var% to $var, $var; or ${var}. Rather than making any radical changes, I've simply removed the requirement for a deref end char. That is, both of the forms demonstrated below are valid:
- Changed default SendMode to Input. This is typically the fastest and most reliable, which is why "SendMode Input" has been included in the "New AutoHotkey Script" template for quite some time. Furthermore, since Unicode support was added, most modes of Send uses SendInput() internally for any character that has no corresponding key-combination. SendInput has been the default mode for hotstrings for a while.
- Since EnvAdd and EnvSub have been removed, the date math functionality was moved to DateAdd() and DateDiff(). These are more or less equivalent to the old EnvAdd and EnvSub commands (or DateTime += Time, TimeUnits and DateTime1 -= DateTime2, TimeUnits), except that the result is returned (not assigned to the first parameter), and all parameters are required.
- If Expression, Command is now a valid If statement with same-line action, since the late IfEqual and related commands had this capability. The comma is required.
- Var declarations (using local/global/static) require := rather than =, for consistency and clarity.
- The GetKeyState command now returns 0 or 1 instead of U or D, so it is equivalent to the GetKeyState() function.
- Mouse wheel hotkeys set A_EventInfo to the delta value reported by the OS, instead of dividing it by 120 (which can lose precision, depending on the hardware and driver).
- DllCall's AStr type is now input-only, since it had very counter-intuitive restrictions as an input-output type. Specifically, the temporary buffer which was allocated to hold the Unicode->ANSI converted string was only long enough to hold the input string. (If the input string was "", the buffer was too small to receive any output value.) This change should improve performance.
- GroupAdd's Label parameter was removed. See www.autohotkey.com/forum/topic61362.html.
- #Include is now relative to the directory containing the current file, by default.
- Multi-statement comma now returns the result of its rightmost sub-statement instead of its leftmost sub-statement. For example, x := (y(), z()) is now equivalent to y(), x := z() instead of x := y(), z().
verb := "Hello" subject := "World" MsgBox [color=darkred]%verb%[/color], [color=darkred]%subject%[/color]! MsgBox [color=darkred]%verb[/color], [color=darkred]%subject[/color]!This also applies to double-derefs in expressions, so %func() is the same as %func%().
Finally, handling of data types has been revised for consistency and flexibility:
All integers and floating-point numbers are pure. For example, MsgBox % 0x1 and MsgBox % (0+1) are both equivalent to MsgBox 1, while MsgBox % 1.0 is equivalent to MsgBox 1.000000. Storing a number in a variable or returning it from a UDF retains its pure numeric status.
When converting a value to a boolean value, quoted numeric strings are evaluated as numbers. Unlike v1, the quoted literal string "0" is considered false.
Numeric operations are capable of working with numeric strings. For example, ("0x" Chr(65)) + 1 in v2 is 11, whereas in v1 it failed because concatenating a quoted literal string with some other value yielded a "pure not numeric" value.
Relational operators such as =, < and >= work a little differently. If one operand is a pure number and the other is - or can be converted to - a number, they are compared numerically. Otherwise, they are compared alphabetically. So for example, 54 and "530" are compared numerically, while "54" and "530" are compared alphabetically. Additionally, strings stored in variables are treated no differently from literal strings.
Type(Value) returns one of the following strings: String, Integer, Float, Object, FileObject, ComObject.