public class Win32Hook {[DllImport ( "kernel32")] public static extern int GetCurrentThreadId (); [DllImport ( "user32", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] public static extern int SetWindowsHookEx (HookType idHook, HOOKPROC lpfn, int hmod, int dwThreadId); public enum HookType {WH_KEYBOARD = 2} public delegate int HOOKPROC (int nCode, int wParam, int lParam); public void SetHook () {// set the keyboard hook SetWindowsHookEx (HookType.WH_KEYBOARD, New hookProc (this.mykeyboard ";} public int mykeyboardProc (int ncode, int wparam, int lparam) {// placed here to process the code Return 0;}} How to use can be in Form Win32HOOK HOOK = New Win32HOOK (); hook.sethook ();