示例#1
0
        //private int lx = 0, ly = 0;
        private IntPtr mHookReception(int nCode, IntPtr wParam, IntPtr lParam)
        {
            Task.Delay(0).ContinueWith((t) =>
            {
                lock (this)
                {
                    if (nCode >= 0)
                    //&& MouseMessages.WM_LBUTTONDOWN == (MouseMessages)wParam)
                    {
                        MSLLHOOKSTRUCT hookStruct = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));
                        int x          = hookStruct.pt.x, y = hookStruct.pt.y;
                        MouseAction ma = (MouseAction)wParam;
                        //Console.WriteLine(ma.ToString());
                        //const int MAXRANGE = 25; // sometimes mouse move reports 0, 0
                        //if (x == 0 && y == 0 && Math.Abs(lx - x) > MAXRANGE &&
                        //    Math.Abs(ly - y) > MAXRANGE && ma == MouseAction.WM_MOUSEMOVE) return;
                        //lx = x; ly = y;
                        if (x == 0 && y == 0)
                        {
                            Win32Point p = new Win32Point();
                            GetCursorPos(ref p);
                            x = p.X;
                            y = p.Y;
                        }

                        foreach (var fn in onMouse)
                        {
                            fn(ma, hookStruct.pt.x, hookStruct.pt.y);
                        }
                        //Console.WriteLine(hookStruct.pt.x + ", " + hookStruct.pt.y);
                    }
                }
            });
            return(CallNextHookEx(_mhookID, nCode, wParam, lParam));
        }
示例#2
0
        /// <summary>
        /// Equality function
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public bool Equals(MSLLHOOKSTRUCT p)
        {
            // If parameter is null return false:
            if ((object)p == null)
            {
                return(false);
            }

            // Return true if the fields match:
            return(Equality(this, p));
        }
示例#3
0
        /// <summary>
        /// Equals override
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            // If parameter is null return false.
            if (obj == null)
            {
                return(false);
            }
#pragma warning disable 168
            var p = new MSLLHOOKSTRUCT();
            try {
                p = (MSLLHOOKSTRUCT)obj;
            }
            catch (InvalidCastException e) {
                return(false);
            }
#pragma warning restore 168

            // Return true if the fields match:
            return(Equality(this, p));
        }
示例#4
0
 static bool Equality(MSLLHOOKSTRUCT a, MSLLHOOKSTRUCT b)
 {
     return((a.pt == b.pt) && (a.mouseData == b.mouseData) && (a.flags == b.flags) && (a.time == b.time) &&
            (a.dwExtraInfo == b.dwExtraInfo));
 }