#Requires [v1.1.33+]

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

#Requires Requirement

매개변수

Requirement

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:

Error Message

The message shown depends on the version of AutoHotkey interpreting the directive.

[v1.1.33+]: The current AutoHotkey version is shown only if a different version of AutoHotkey is required.

[v1.1.36+]: 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).

A trailing "+" is sufficient to indicate to the reader that later versions are acceptable, but is not required.

다른 지시어처럼, #Requires는 조건적으로 실행할 수 없습니다.

VerCompare(), #ErrorStdOut

예제

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

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

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

#Requires AutoHotkey >=1.1.36 <1.2

Causes the script to run only with a 64-bit interpreter (EXE).

#Requires AutoHotkey 64-bit

Causes the script to run only with a 64-bit interpreter (EXE) version 1.1.36.00 or later.

#Requires AutoHotkey v1.1.36 64-bit