/// <summary> /// Creates a new instance of the MouseHook class /// </summary> public MouseHook() { // Create an instance of HookProc. HookProc MouseHookProcedure = new HookProc(MouseHookProc); // setting the hook //HookHandle = User32API.SetWindowsHookEx(HookType.WH_MOUSE, MouseHookProcedure, (IntPtr)0, AppDomain.GetCurrentThreadId()); HookHandle = User32API.SetWindowsHookEx(HookType.WH_MOUSE_LL, MouseHookProcedure, Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]), 0); //If SetWindowsHookEx fails. if (HookHandle == 0) { System.Windows.Forms.MessageBox.Show("hook failed"); //return; } }