Please, can anyone explain me:
- what is Keyboard hook
- what allow Keyboard hook
- when is necessary use Keyboard hook?
Thank you very much
What is keyboard hook?
Re: What is keyboard hook?
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...
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...
Re: What is keyboard hook?
the keyboard hook https://github.com/AutoHotkey/AutoHotkey/blob/8f8332238f92722a1c0c4c05bcf586993be375af/source/hook.cpp#L4303
is the code ahk runs in response to "low level keyboard event" forwarded to it by windows
https://github.com/AutoHotkey/AutoHotkey/blob/8f8332238f92722a1c0c4c05bcf586993be375af/source/hook.cpp#L157-L286
https://github.com/AutoHotkey/AutoHotkey/blob/8f8332238f92722a1c0c4c05bcf586993be375af/source/hook.cpp#L368-L1951
is the code ahk runs in response to "low level keyboard event" forwarded to it by windows
https://github.com/AutoHotkey/AutoHotkey/blob/8f8332238f92722a1c0c4c05bcf586993be375af/source/hook.cpp#L157-L286
https://github.com/AutoHotkey/AutoHotkey/blob/8f8332238f92722a1c0c4c05bcf586993be375af/source/hook.cpp#L368-L1951
Re: What is keyboard hook?
I have already cited the "dollar prefix" section, but here it is once again.
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.
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
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.