/// <summary>
 /// Unregisters the winapi hook for global mouse events
 /// </summary>
 private void UnregisterMouseHook()
 {
     if (hookID == IntPtr.Zero)
     {
         return;
     }
     NativeMethodsMouse.UnhookWindowsHookEx(hookID);
     hookID = IntPtr.Zero;
 }
        /// <summary>
        /// Registers the function HookCallback for the global mouse events winapi
        /// </summary>
        private void RegisterMouseHook()
        {
            if (hookID != IntPtr.Zero)
            {
                return;
            }

            proc = new NativeMethodsMouse.HookHandlerDelegate(HookCallback);
            using (Process curProcess = Process.GetCurrentProcess())
            {
                using (ProcessModule curModule = curProcess.MainModule)
                {
                    hookID = NativeMethodsMouse.SetWindowsHookEx(NativeMethodsMouse.WH_MOUSE_LL, proc,
                                                                 NativeMethodsKeyboard.GetModuleHandle(curModule.ModuleName), 0);
                }
            }
        }
        /// <summary>
        /// Processes the key event captured by the hook.
        /// </summary>
        private IntPtr HookCallback(int nCode,
                                    UIntPtr wParam,
                                    ref NativeMethodsMouse.MSLLHOOKSTRUCT lParam)
        {
            if (nCode == NativeMethodsMouse.HC_ACTION)
            {
                MouseRawEventArgs args = new MouseRawEventArgs(lParam);
                args.ParseWparam(wParam);
                CheckDoubleClick(args);

                Log.e("ME", String.Format("MOUSE: Button:{0} Action:{1} Orig:{2}",
                                          args.Button.ToString(), args.Action.ToString(),
                                          args.Event.ToString()));

                OnMouseEvent(args);
            }
            return(NativeMethodsMouse.CallNextHookEx(hookID, nCode, wParam, ref lParam));
        }
 /// <summary>
 /// Set up the mouse hook
 /// </summary>
 public MouseHook()
 {
     doubleClickTime = NativeMethodsMouse.GetDoubleClickTime();
     Log.e("ME", "doubleClickTime " + doubleClickTime.ToString());
     RegisterMouseHook();
 }