Exemple #1
0
        private static int MouseHookProc(int nCode, int wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                HookManager.MouseLLHookStruct structure = (HookManager.MouseLLHookStruct)Marshal.PtrToStructure(lParam, typeof(HookManager.MouseLLHookStruct));
                MouseButtons buttons = MouseButtons.None;
                short        num     = 0;
                int          clicks  = 0;
                bool         flag1   = false;
                bool         flag2   = false;
                switch (wParam)
                {
                case 513:
                    flag1   = true;
                    buttons = MouseButtons.Left;
                    clicks  = 1;
                    break;

                case 514:
                    flag2   = true;
                    buttons = MouseButtons.Left;
                    clicks  = 1;
                    break;

                case 515:
                    buttons = MouseButtons.Left;
                    clicks  = 2;
                    break;

                case 516:
                    flag1   = true;
                    buttons = MouseButtons.Right;
                    clicks  = 1;
                    break;

                case 517:
                    flag2   = true;
                    buttons = MouseButtons.Right;
                    clicks  = 1;
                    break;

                case 518:
                    buttons = MouseButtons.Right;
                    clicks  = 2;
                    break;

                case 522:
                    try
                    {
                        num = (short)(structure.MouseData >> 16 & (int)ushort.MaxValue);
                        break;
                    }
                    catch (Exception ex)
                    {
                        break;
                    }
                }
                MouseEventExtArgs e = new MouseEventExtArgs(buttons, clicks, structure.Point.X, structure.Point.Y, (int)num);
                if (HookManager.s_MouseUp != null && flag2)
                {
                    HookManager.s_MouseUp((object)null, (MouseEventArgs)e);
                }
                if (HookManager.s_MouseDown != null && flag1)
                {
                    HookManager.s_MouseDown((object)null, (MouseEventArgs)e);
                }
                if (HookManager.s_MouseClick != null && clicks > 0)
                {
                    HookManager.s_MouseClick((object)null, (MouseEventArgs)e);
                }
                if (HookManager.s_MouseClickExt != null && clicks > 0)
                {
                    HookManager.s_MouseClickExt((object)null, e);
                }
                if (HookManager.s_MouseDoubleClick != null && clicks == 2)
                {
                    HookManager.s_MouseDoubleClick((object)null, (MouseEventArgs)e);
                }
                if (HookManager.s_MouseWheel != null && num != (short)0)
                {
                    HookManager.s_MouseWheel((object)null, (MouseEventArgs)e);
                }
                if ((HookManager.s_MouseMove != null || HookManager.s_MouseMoveExt != null) && (HookManager.m_OldX != structure.Point.X || HookManager.m_OldY != structure.Point.Y))
                {
                    HookManager.m_OldX = structure.Point.X;
                    HookManager.m_OldY = structure.Point.Y;
                    if (HookManager.s_MouseMove != null)
                    {
                        HookManager.s_MouseMove((object)null, (MouseEventArgs)e);
                    }
                    if (HookManager.s_MouseMoveExt != null)
                    {
                        HookManager.s_MouseMoveExt((object)null, e);
                    }
                }
                if (e.Handled)
                {
                    return(-1);
                }
            }
            return(HookManager.CallNextHookEx(HookManager.s_MouseHookHandle, nCode, wParam, lParam));
        }