#Requires [v1.1.33+]

Displays an error and quits if a version requirement is not met.

#Requires Requirement

Parameters

Requirement

If this begins with the word "AutoHotkey" followed by a space or tab, it should be followed by a version string with optional leading "v". If A_AhkVersion is deemed compatible, loading of the script continues without displaying an error. For example, a script that requires v1.1.33 will also run on v1.1.33.01 and v1.1.34, but not v2.0.

Otherwise, an error message is shown and the program exits.

Error Message

If a different version of AutoHotkey is required, the message includes A_AhkVersion:

This script requires %Requirement%, but you have v%A_AhkVersion%.

If the requirement was not recognized, the message format is as follows:

This script requires %Requirement%.

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.

Remarks

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, a launcher script might use 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).

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.

#ErrorStdOut

Examples

Causes the script to run only on v1.1.33.00 and later v1.1.* releases.

#Requires AutoHotkey v1.1.33+
MsgBox This script will run only on v1.1.33.00 and later v1.1.* releases.