Windows Hooker API

<< Back to the Windows Hooker page

Using the library

  • Include a COM reference to the WindowsHooker 1.0 Type Library
  • place the following at the beginning of your program: using WINDOWSHOOKERLib;

The HookManager Object

You must create a HookManager object, which you then use to access the API, to start and stop hooking and logging, and to attach event handlers to.

  • private HookManager hm = new HookManager ();

Starting/Stopping the Hook plus Logging operations

You can start and stop hooking, and you can turn mouse and/or key logging on and off

hm.LogKeyboard = (boolean)

  • true to start logging keypresses, false to stop.
  • e.g., hm.LogKeyboard = true;

hm.LogMouse = (boolean)

  • true to start logging mice actions, false to stop.
  • e.g., hm.LogMouse = true;


  • start the hooking
  • should be called after all the LogKeyboard / LogMouse states are set and after the event handlers are created

hm.StopWindowsHook ()

  • stop the hooking - should be called before exiting the program to stop the hook
  • e.g., in a FormClosing event

Event Handlers

The object will automatically generate events whenever it detects mouse / key actions. However, you have to attach event handlers if you want to do something with these events.


  • attach an event handler to a detected Mouse Down event.
  • hm.MouseDown += new _IHookManagerEvents_MouseDownEventHandler(hm_MouseDown);
  • void hm_MouseDown(int x, int y, int hWnd, int MouseMessage, int HitTestCode, int dwExtraInfo) {}
    • x,y: The position of the cursor in screen coordinates
    • hWnd: A pointer to the current window selected
    • MouseMessage: Indicates the button pressed (Left, Right, Middle, XButton1, XButton2)
    • HitTestCode: Indicates if the cursor is directly under any window
    • dwExtraInfo: Contains extra information (e.g., Mouse Wheel Delta)
    • For more information visit


  • as above, but for a Mouse Up event


  • as above, but for other Mouse events such as Mouse Wheel


  • attach an event handler to a detected Key Down event.
  • hm.KeyDown += new _IHookManagerEvents_KeyDownEventHandler(hm_KeyDown);
  • void hm_KeyDown(int VirtualKeyCode, int Scancode, int RepeatCount, bool KeyPressed, bool PreviousKeyWasDown, bool AltDown, bool ExtendedKey) {}

hm.KeyUp (

  • as above, but for Key Up events


  • as above, but for other Key events