Search code examples
c#winformshookkeyboard-hook

How to make global keyboard hook for key combinations?


I'm using it to make global keyboard hook. There are such lines :

gkh.HookedKeys.Add(Keys.A);
gkh.HookedKeys.Add(Keys.B);

to register hooked hotkeys. How to modify that solution to make hook for combination, for example A+B, but not single A or B?


Solution

  • The standard solution for global hotkeys is the RegisterHotkey API. It supports hotkeys with modifiers (Control, Shift, Alt, Windows) out of the box, and doesn't suffer from the global side effects of a hook.