Ejemplo n.º 1
0
        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);
                }
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
0
 public void Dispose()
 {
     User32Interop.UnhookWindowsHookEx(this._hookId);
 }