Esempio n. 1
0
        private IntPtr HookCallback(int nCode, IntPtr wParam, ref MOUSEINPUT lParam)
        {
            if (nCode >= 0)
            {
                INPUT input = new INPUT
                {
                    dwType = (Int32)InputType.Mouse,
                    mi     = lParam
                };
                POINT p = new POINT();
                Win32.GetCursorPos(out p);
                input.mi.dx = (p.X - oldX);
                input.mi.dy = (p.Y - oldY);
                oldX        = p.X;
                oldY        = p.Y;
                //if (MouseEvent != null) MouseEvent(this, input);
                int message = (int)wParam;
                input.mi.time        = 0;
                input.mi.dwExtraInfo = IntPtr.Zero;
                switch (message)
                {
                case WM_LBUTTONDOWN:
                    input.mi.dwFlags   = MOUSEEVENTF_LEFTDOWN;
                    input.mi.mouseData = 0;
                    if (LeftDown != null)
                    {
                        LeftDown(this, input);
                    }
                    break;

                case WM_LBUTTONUP:
                    input.mi.dwFlags   = MOUSEEVENTF_LEFTUP;
                    input.mi.mouseData = 0;
                    if (LeftUp != null)
                    {
                        LeftUp(this, input);
                    }
                    break;

                case WM_RBUTTONDOWN:
                    input.mi.dwFlags   = MOUSEEVENTF_RIGHTDOWN;
                    input.mi.mouseData = 0;
                    if (RightDown != null)
                    {
                        RightDown(this, input);
                    }
                    break;

                case WM_RBUTTONUP:
                    input.mi.dwFlags   = MOUSEEVENTF_RIGHTUP;
                    input.mi.mouseData = 0;
                    if (RightUp != null)
                    {
                        RightUp(this, input);
                    }
                    break;

                case WM_MBUTTONDOWN:
                    input.mi.dwFlags   = MOUSEEVENTF_MIDDLEDOWN;
                    input.mi.mouseData = 0;
                    if (MediumDown != null)
                    {
                        MediumDown(this, input);
                    }
                    break;

                case WM_MBUTTONUP:
                    input.mi.dwFlags   = MOUSEEVENTF_MIDDLEUP;
                    input.mi.mouseData = 0;
                    if (MediumUp != null)
                    {
                        MediumUp(this, input);
                    }
                    break;

                case WM_MBUTTONDBLCLK:
                    input.mi.mouseData = 0;
                    if (MediumDoubleClick != null)
                    {
                        MediumDoubleClick(this, input);
                    }
                    break;

                case WM_LBUTTONDBLCLK:
                    input.mi.mouseData = 0;
                    if (LeftDoubleClick != null)
                    {
                        LeftDoubleClick(this, input);
                    }
                    break;

                case WM_RBUTTONDBLCLK:
                    input.mi.mouseData = 0;
                    if (RightDoubleClick != null)
                    {
                        RightDoubleClick(this, input);
                    }
                    break;

                case WM_MOUSEMOVE:
                    input.mi.mouseData   = 0;
                    input.mi.dwFlags     = MOUSEEVENTF_MOVE;
                    input.mi.dwExtraInfo = IntPtr.Zero;
                    if (Move != null)
                    {
                        Move(this, input);
                    }
                    break;

                case WM_MOUSEWHEEL:
                    input.mi.mouseData = (short)((input.mi.mouseData >> 16) & 0xffff);
                    input.mi.dwFlags   = MOUSEEVENTF_WHEEL;
                    if (Wheel != null)
                    {
                        Wheel(this, input);
                    }
                    break;
                }
                if (MouseEvent != null)
                {
                    MouseEvent(this, input);
                }
            }
            return(CallNextHookEx(hookHandle, nCode, wParam, ref lParam));
        }
Esempio n. 2
0
 public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, ref MOUSEINPUT lParam);