Ejemplo n.º 1
0
        private IntPtr HookCallback(
            int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                MSLLHOOKSTRUCT hookStruct = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));

                if (
                    _oldLocation.x != hookStruct.pt.x ||
                    _oldLocation.y != hookStruct.pt.y
                    )
                {
                    _oldLocation = hookStruct.pt;

                    var p = new HookMouseEventArg
                    {
                        Point   = new Point(hookStruct.pt.x, hookStruct.pt.y),
                        Handled = false
                    };

                    OnMouseMove(p);

                    if (p.Handled)
                    {
                        return(new IntPtr(-1));
                    }
                }
            }
            return(CallNextHookEx(_hookId, nCode, wParam, lParam));
        }
Ejemplo n.º 2
0
 protected virtual void OnMouseMove(HookMouseEventArg args)
 {
     MouseMove?.Invoke(this, args);
 }