public void InstallMouseHook()
        {
            using (var currentProcess = Process.GetCurrentProcess())
                using (var currentModule = currentProcess.MainModule)

                {
                    var moduleHandle = Kernel32Interop.GetModuleHandle(currentModule.ModuleName);
                    this._hookId = User32Interop.SetWindowsHookEx(WH_MOUSE_LL, MouseHookCallback, moduleHandle, 0);
                }
        }
        private IntPtr MouseHookCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0 && Messages.WM_LBUTTONDOWN == (Messages)wParam)
            {
                _stopwatch.Reset();
                _stopwatch.Start();
            }

            if (nCode >= 0 && Messages.WM_LBUTTONUP == (Messages)wParam)
            {
                _stopwatch.Stop();
            }

            return(User32Interop.CallNextHookEx(this._hookId, nCode, wParam, lParam));
        }
 public void Dispose()
 {
     User32Interop.UnhookWindowsHookEx(this._hookId);
 }