Desktop Functions:

   Smart Device Functions:

Show Recent Changes
Subscribe (RSS)
Misc. Pages
1` DF
Helpful Tools
Suggested Reading
Website TODO List
Download Visual Studio Add-In

SetWindowsHookEx (user32)
Installs a hook to monitor certain types of events.

C# Signature:

[DllImport("user32.dll")] public static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);

Alternative Managed API:

The ManagedWindowsApi project ( provides a Hook class and subclasses for Journal hooks, Message hooks and Low-Level hooks.


SetWindowsHookEx on MSDN

MSDN example of a mouse hook in C#:;en-us;318804#3

MSDN article on hooks in .NET:

MSDN article on KeyboardProc:

Stephen Toub entry on low-level keyboard hook in C#:

Stephen Toub entry on low-level mouse hook on C#:


Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

Access directly from VS:
Terms of Use
Find References
Show Printable Version