What is keyboard hook?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Archimede
Posts: 512
Joined: 25 Nov 2021, 09:49
Location: Switzerland / Italy

What is keyboard hook?

Post by Archimede » 21 Mar 2023, 09:05

Please, can anyone explain me:
- what is Keyboard hook
- what allow Keyboard hook
- when is necessary use Keyboard hook?
Thank you very much

User avatar
mikeyww
Posts: 27094
Joined: 09 Sep 2014, 18:38

Re: What is keyboard hook?

Post by mikeyww » 21 Mar 2023, 09:09

KeyboardHook.png
How to use the AHK documentation to search for information
KeyboardHook.png (275.49 KiB) Viewed 781 times

Dollar

Archimede
Posts: 512
Joined: 25 Nov 2021, 09:49
Location: Switzerland / Italy

Re: What is keyboard hook?

Post by Archimede » 21 Mar 2023, 09:14

Sorry.
I red it but I no understood anything about...
I no understand when I need to use any directive about the hook, like #UseHook ON, #InstallKeybdHook and so on...
:-(


User avatar
mikeyww
Posts: 27094
Joined: 09 Sep 2014, 18:38

Re: What is keyboard hook?

Post by mikeyww » 21 Mar 2023, 09:35

I have already cited the "dollar prefix" section, but here it is once again.
This is usually only necessary if the script uses the Send command to send the keys that comprise the hotkey itself, which might otherwise cause it to trigger itself. The $ prefix forces the keyboard hook to be used to implement this hotkey, which as a side-effect prevents the Send command from triggering it. The $ prefix is equivalent to having specified #UseHook somewhere above the definition of this hotkey.

The $ prefix has no effect for mouse hotkeys, since they always use the mouse hook. It also has no effect for hotkeys which already require the keyboard hook, including any keyboard hotkeys with the tilde (~) or wildcard (*) modifiers, key-up hotkeys and custom combinations. To determine whether a particular hotkey uses the keyboard hook, use ListHotkeys.

Code: Select all

#Requires AutoHotkey v1.1.33
a::Send a
$b::Send b

#UseHook
c::
d::Send % A_ThisHotkey
#UseHook Off
I have found a few other situations where the hook helps, but if your script works without it, you don't need to bother with it.

From documentation: if the script does not have the keyboard hook installed, the KeyHistory window will display only the keyboard events generated by the script itself (not the user's). If the script does not have the mouse hook installed, mouse button events will not be shown. If the keyboard hook is not installed when KeyWait is used and a keyboard key is released artificially by means such as the Send command, the key will be seen as having been physically released. If neither hook is installed, A_TimeIdlePhysical is equivalent to A_TimeIdle. If only one hook is installed, only its type of physical input affects A_TimeIdlePhysical. The non-installed hook's input, both physical and artificial, has no effect.

Post Reply

Return to “Ask for Help (v1)”