Forces the unconditional installation of the keyboard hook.
#InstallKeybdHook |
Remarks
The keyboard hook monitors keystrokes for the purpose of activating hotstrings and any keyboard hotkeys not directly supported by RegisterHotkey (which is a function built into the operating system). It also supports a few other features such as the Input command.
The keyboard hook is not supported under Windows 95/98/Me because those operating systems require a different type of hook that must reside in a DLL file.
AutoHotkey does not install the keyboard and mouse hooks unconditionally because together they consume at least 500 KB of memory and might very slightly impact system performance. Therefore, the keyboard hook is normally installed only when the script contains one of the following: 1) hotstrings; 2) one or more hotkeys that require the keyboard hook (most do not); 3) SetCaps/Scroll/Numlock AlwaysOn/AlwaysOff; 4) the Input command, for which the hook is installed upon first actual use.
By contrast, the #InstallKeybdHook directive will unconditionally install the keyboard hook, which might be useful to allow KeyHistory to display the last 20 keystrokes (for debugging purposes), or to avoid the need for #HotkeyModifierTimeout.
You can determine whether a script is using the hook via the KeyHistory command or menu item. You can determine which hotkeys are using the hook via the ListHotkeys command or menu item.
This directive also makes a script persistent, meaning that ExitApp should be used to terminate it.
Related
#InstallMouseHook, #UseHook, Hotkey, Input, #Persistent, KeyHistory, Hotstrings, GetKeyState, KeyWait
Example
#InstallKeybdHook