Ejemplo n.º 1
0
        public bool HookMouse()
        {
            if (HookRegistered)
            {
                return(true);
            }

            bool result = false;

            _del = (int code, long wParam, ref MSLLHOOKSTRUCT lParam) =>
            {
                // If the code is less than 0, Windows want it to be processed without touching..
                // https://msdn.microsoft.com/en-us/library/windows/desktop/ms644985(v=vs.85).aspx
                if (code < 0)
                {
                    return(CallNextHookEx(IntPtr.Zero, code, wParam, ref lParam));
                }

                OnMouseInputChanged(this, new MouseInputArgs(wParam, lParam.pt, lParam.flags));
                return(CallNextHookEx(IntPtr.Zero, code, wParam, ref lParam));
            };

            IntPtr handle = GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName);

            HHook = SetWindowsHookEx(HookType.WH_MOUSE_LL, _del, handle, 0);

            if (HHook == IntPtr.Zero)
            {
                // Write to file?
                var myerror = Marshal.GetLastWin32Error();
            }
            else
            {
                result         = true;
                HookRegistered = true;
            }

            return(result);
        }
Ejemplo n.º 2
0
 static extern IntPtr SetWindowsHookEx(
     HookType hookType
     , MouseLLHookHandler lpfn
     , IntPtr hMod
     , uint dwThreadId
     );