7

I was reading the Doc of Autohotkey and then I was not able to understand the meaning of the phrase 'keyboard hook' or 'mouse hook'.

this is the text:

"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"

URL: https://www.autohotkey.com/docs/Hotkeys.htm

Muaath Alhaddad
  • 341
  • 2
  • 14

2 Answers2

4

1 - A Keyboard Hook or Mouse Hook that Means: that you can monitor/receive all the keyboard keypress values or that you monitor all the mouse button press values

Note: you will need to use the command code #InstallKeybdHook to enable the monitor

And for the Mouse Hook you will need to use the command code #InstallMouseHook

try this AHK Code:

Example.ahk

#SingleInstance force
#InstallKeybdHook

$^c::
send ^c
send {f5}
return

esc::exitapp

2 - And the $ prefix means that you can use the Hotkey ($^c::) into the same hotkey code (send ^c).

How to Monitor All your Keyboard press values:

1 - go to the System Tray.(Autohotkey Icon)

2 - then click right mouse button.

3 - then go to open.

4 - then click left mouse button.

5 - then click Ctrl+c

6 - Now you will see the Keyboard Hook that you clicked.

keyboard hook

Note: For Monitor All the Keyboard KeyPress Values you will need to manually press the (F5) Key (Refresh)

Community
  • 1
  • 1
stevecody
  • 658
  • 1
  • 6
  • 18
2

Type of hotkey (in autohotkey)

a. reg

  • reg: The hotkey is implemented via the operating system's RegisterHotkey() function.
  • reg(no): Same as above except that this hotkey is inactive (due to being unsupported, disabled, or suspended).

RegisterHotKey function (winuser.h)
from microsoft

BOOL RegisterHotKey(
  [in, optional] HWND hWnd,
  [in]           int  id,
  [in]           UINT fsModifiers,
  [in]           UINT vk
);

b. hook

  • k-hook: The hotkey is implemented via the keyboard hook.
  • m-hook: The hotkey is implemented via the mouse hook
  • 2-hooks: The hotkey requires both the hooks mentioned above

keyboard hook

it monitors keystrokes, for the purpose of activating:

  1. hotstrings
  2. keyboard hotkeys not supported by RegisterHotkey
  3. It also supports a few other features such as the Input command

When keyboard hook is used

here says:
The most recently registered hook gets called first.
The most recently started script doesn't necessarily take precedence, since hook hotkeys always take precedence over registered hotkeys.
AutoHotkey use the hook when:

  1. instructed to use it (#UseHook or $),
  2. automatically if the script uses #IfWin
  3. if the hotkey can't be registered.

Further reference:

SetWindowsHookEx

https://learn.microsoft.com/en-us/windows/win32/winmsg/about-hooks

To take advantage of a particular type of hook, the developer provides a hook procedure and uses the SetWindowsHookEx function to install it into the chain associated with the hook

SetWindowsHookExA function (winuser.h)

https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowshookexa?redirectedfrom=MSDN

similar question about C#:

RegisterHotKeys and global keyboard hooks?

a

https://www.autohotkey.com/boards/viewtopic.php?t=68550

Good Pen
  • 625
  • 6
  • 10