#UseHook - Syntax & Usage | AutoHotkey

AutoHotkey

#UseHook

Forces the use of the hook to implement all or some keyboard hotkeys.

#UseHook On|Off

Parameters

On|Off

#UseHook without one of the following words after it is equivalent to #UseHook On.

On: The keyboard hook will be used to implement all keyboard hotkeys between here and the next #UseHook OFF (if any).

Off: Hotkeys will be implemented using the default method (RegisterHotkey() if possible; otherwise, the keyboard hook).

Remarks

Normally, the windows API function RegisterHotkey() is used to implement a keyboard hotkey whenever possible. However, the responsiveness of hotkeys might be better under some conditions if the keyboard hook is used instead.

Turning this directive ON is equivalent to using the $ prefix in the definition of each affected hotkey.

As with all # directives -- which are processed only once when the script is launched -- #UseHook should not be positioned in the script as though it were a command (that is, it is not necessary to have it contained within a subroutine). Instead, position it immediately before the first hotkey label you wish to have affected by it.

By default, hotkeys that use the keyboard hook cannot be triggered by means of the Send command. Similarly, mouse hotkeys cannot be triggered by commands such as Click because all mouse hotkeys use the mouse hook. One workaround is to use Gosub to jump directly to the hotkey's subroutine. For example: Gosub #LButton.

[v1.1.06+]: #InputLevel and SendLevel provide additional control over which hotkeys and hotstrings are triggered by the Send command.

If this directive does not appear in the script at all, it will behave as though set to OFF.

Related

#InstallKeybdHook, #InstallMouseHook, ListHotkeys, #InputLevel

Example

#UseHook  ; Force the use of the hook for hotkeys after this point.
#x::MsgBox, This hotkey will be implemented with the hook.
#y::MsgBox, And this one too.
#UseHook off
#z::MsgBox, But not this one.