Thoughts for v2.0

There are some small potential changes to be made. All of the big changes have been done or deferred.

The remainder of this document is about changes that were originally considered for v2.0 but were deferred for various reasons.


The following potential changes will most likely not be included in the initial v2.0 release. They will be considered for inclusion in a later release, such as v2.1, or v2.0.x if backward-compatible.

Catch and For loop variables

Currently Catch and For loop variables are "backed up" prior to executing the body of the statement and restored afterward, as an approximation of making the variable "local" to the statement. Ideally they would be actually local and independent of any variable with the same name outside the block. The difference can be observed when the block calls a function which references the same variable (perhaps it is a nested function or the variable is global).

Any kind of hacks to just make the variable names scoped to the block won't play well with closures, so this is being deferred until proper block-scoped variables can be implemented.


Gui.AddControl and GuiControl.Add currently require an array, but it would be trivial to support any enumerable object.

Maybe change WinGetID to WinGetHwnd for consistency with various other things. On the other hand, I don't want it to be inconsistent with ahk_id, and don't want to change that to ahk_hwnd. Reconsider this if the ahk_ WinTitle scheme is ever updated or removed.

FileGetShortcut and FileCreateShortcut have too many parameters, but I haven't decided whether to change them or just replace both with a function to get a ShellLinkObject (through COM), either built-in or as a trivial script. ShellLinkObject has all the same capabilities plus a Hotkey property and maybe others.

SplitPath could return an object when no output parameters are passed. Property names are probably easier to remember than parameter order, and easier to read and write than counting commas. This should have no negative impact on compatibility if added later, presuming scripts do not rely on SplitPath returning "".

The error dialog may be improved to make debugging easier. An example implementation, details and ideas can be found at GitHub/Lexikos/Object.ahk.

WinTitle and Window Groups

Background info: Each window group consists of a list of window specs. A window spec in v1 consists of WinTitle, WinText, ExcludeTitle and ExcludeText. Window specs are evaluated in the order they were added to the group. For convenience, "rule" means "window spec" in the text below.


Problems in v1:

The most likely solution is to introduce "negative" or "exclusive" rules. Rules are evaluated in the order they were added to the group, ending with the first rule (positive or negative) that matches the window. This provides the following benefits:

There are different ways this could be achieved:

Chris' comments:

ExcludeTitle doesn't support ahk_pid and similar things. All it does is what the help file says: "Windows whose titles include this value will not be considered." The reason for this is that the added code size doesn't seem justified given how rarely ExcludeTitle is used.

In either case, a negative rule has no effect if there aren't any positive rules following it, because the absence of any subsequent positive rules means that the window won't be a match anyway. Therefore, for convenience, a group could match all windows by default if the last rule is negative. That way, if group N contains only negative rules, ahk_group N matches all windows except those excluded by the group (instead of always matching nothing at all).

Some other ideas might supersede all considerations about ExcludeTitle/ExcludeText:


An oft-requested feature is to allow global settings such as SetTitleMatchMode, DetectHiddenWindows and DetectHiddenText to be overruled temporarily for a given WinTitle or command. At the moment, the most likely form it could take is Title ahk_mode 3 ahk_dhw 1. Implementing this in a later release is unlikely to affect existing scripts; therefore this is not currently planned for v2.0.

Expression Operators

Current thoughts as of 2020: This functionality is probably better off as methods of certain objects, such as arr.IndexOf(value) instead of value in arr.

Although in and contains are already reserved in v2-alpha (so adding them later won't break anything), v2 might seem incomplete without them, since users converting existing scripts from v1 (or just used to using v1) will need to find some alternative that works in v2. They should probably be implemented before the v2.0 release, and they should be updated to be more modern (allow arrays).

Current usage: if var [not] in/contains MatchList. MatchList is a comma-delimited list. Var contains a string.

It seems logical to allow an array as a direct substitute for MatchList. Someone suggested that the new operators should never accept a comma-delimited list, but in that case a string would be interpreted one of the following ways:

  1. An error.
  2. Equivalent to a single-element array. That would mean:
  3. Equivalent to an array of the string's individual characters. That would mean:
  4. Having different meaning depending on the type of operand. Seems confusing. For example:

If arrays are supported on the left side of contains, how would that work? Traditionally the difference between in and contains is that in does a direct comparison of the value while contains does a substring match. Would arr1 contains arr2 search for each element of arr2 as a substring of each element of arr1? Or check for the existence of any common values between the two? Or all? Or check whether the exact sequence of values in arr2 exists within arr1 as a subset? The last option would be analogous to InStr(str1, str2), but not str1 contains str2.

Some (not very relevant) discussion here:

between probably won't be implemented at any stage. An alternative could be to allow operator chaining as in Python and Perl 6, where x < y < z is equivalent to (x < y) and (y < z). However, that would mean that parentheses would change the meaning of < (which doesn't seem right), such as in x < y < z vs (x < y) < z, because the latter case would compare the result of x < y (true or false) to z. Some users already try x < y < z and wonder at the result, so if it isn't implemented, maybe chained operators should be detected and cause a warning/error. (But if chained operators would be complicated to detect, cost vs benefit seems to be in favour of implementing chaining.)

Binary Strings

Strings beginning with Chr(0) are currently false, because the boolean checks assume a zero-terminated string rather than a binary counted one. Other cases may exist where the string is assumed to be empty.

Any operators or functions which expect a number will read only up to the first binary zero, and therefore may consider a string containing embedded nulls (possibly followed by other non-numeric characters) to be numeric.

In theory, all strings containing binary zero should be considered non-empty and non-numeric.

Deferred because: proper, consistent support for null characters in strings seems to be more work than it is worth (cost outweighs benefit).


When RAlt is pressed or sent, if the active window's keyboard layout has AltGr, the system generates LCtrl-down and LCtrl-up. (It also generates LCtrl-up when switching between keyboard layouts if the previous layout had AltGr, even if the new one also has AltGr.) This has some potentially undesirable consequences:

It is technically possible to identify AltGr's fake LCtrl by utilizing the little-known fact that KBDLLHOOKSTRUCT::scanCode has the 0x200 bit set for the fake LCtrl events. (KeyHistory doesn't show this because the scan code is truncated to 1 byte [and then 0x100 is added if the 0xE0 flag is set].)

It would only take a few lines of code to mark the fake LCtrl events as "ignored", which would avoid all of the "consequences" listed above, except that it would introduce inconsistency between "hook" hotkeys (which would treat AltGr as RAlt) and "reg" hotkeys (hotkeys with ^!key would be triggered by AltGr+key). AltGr would become just RAlt:: or >! (both of which always use the hook) and <^>! would mean LCtrl+AltGr. When only AltGr is down, GetKeyState would report LCtrl as physically up but logically down (reflecting the fact that the user hasn't physically pressed LCtrl, but the active window considers Ctrl to be down).

Deferred because: I don't recall seeing any related issues, and I don't use a layout with AltGr. The possibility of treating AltGr as just RAlt (or treating the LCtrl as non-physical/ignored) can be explored after v2.0, perhaps as an optional mode.

Thread Sub-commands

The Thread function still has sub-commands.

Deferred because: It's used more rarely than WinSet, Control, Drive, etc. so leaving it with sub-commands (extra quote marks) doesn't seem like an issue.

Control Functions

We seem to lack functions for getting/setting the value of external controls of some types, such as Slider, UpDown, MonthCal (I have not tested ControlSetText on these).


ListViewGetContent has usage virtually identical to ControlGet List (when used on a ListView). It would be ideal to provide a similar interface for both external and script-made ListViews. Due to complexity and lack of interest (by me), this is being deferred indefinitely.