Displays an error and quits if a version requirement is not met.
If this does not begin with the word "AutoHotkey", an error message is shown and the program exits. This encourages clarity and reserves the directive for future uses. Other forks of AutoHotkey may support other names.
Otherwise, the word "AutoHotkey" should be followed by any combination of the following, separated by spaces or tabs:
=immediately followed by an optional letter "v" and a version number. For example,
>=2-rc <2allows v2 release candidates but not the final release.
The message shown depends on the version of AutoHotkey interpreting the directive.
For v2, the path, version and build of AutoHotkey are always shown in the error message.
If the script is launched with a version of AutoHotkey that does not support this directive, the error message is something like the following:
Line Text: #Requires %Requirement% Error: This line does not contain a recognized action.
If the script uses syntax or functions which are unavailable in earlier versions, using this directive ensures that the error message shows the unmet requirement, rather than indicating an arbitrary syntax error. This cannot be done with something like
if (A_AhkVersion <= "1.1.33") because a syntax error elsewhere in the script would prevent it from executing.
When sharing a script or posting code online, using this directive allows anyone who finds the code to readily identify which version of AutoHotkey it was intended for.
Other programs or scripts can check for this directive for various purposes. For example, the launcher installed with AutoHotkey v2 uses it to determine which AutoHotkey executable to launch, while a script editor or related tools might use it to determine how to interpret or highlight the script file.
Version strings are compared as a series of dot-delimited components, optionally followed by a hyphen and pre-release identifier(s).
#Requires AutoHotkey v2will not run on v2.0-a112. To permit pre-release versions, include a hyphen suffix. For example:
A trailing "+" is sufficient to indicate to the reader that later versions are acceptable, but is not required.
Like other directives, #Requires cannot be executed conditionally.
#Requires AutoHotkey v2.0-a MsgBox "This script will run only on v2.0, including alpha releases."
#Requires AutoHotkey >=2.0- <2.1