Exemple #1
0
        private static IntPtr Filter(int nCode, IntPtr wParam, IntPtr lParam)
        {
            bool result = true;

            if (nCode >= 0)
            {
                if (wParam == (IntPtr)Hooks.WM_KEYDOWN ||
                    wParam == (IntPtr)Hooks.WM_SYSKEYDOWN)
                {
                    int vkCode = Marshal.ReadInt32(lParam);
                    if ((Keys)vkCode == Keys.LControlKey ||
                        (Keys)vkCode == Keys.RControlKey)
                    {
                        Control = true;
                    }
                    else if ((Keys)vkCode == Keys.LShiftKey ||
                             (Keys)vkCode == Keys.RShiftKey)
                    {
                        Shift = true;
                    }
                    else if ((Keys)vkCode == Keys.RMenu ||
                             (Keys)vkCode == Keys.LMenu)
                    {
                        Alt = true;
                    }
                    else if ((Keys)vkCode == Keys.RWin ||
                             (Keys)vkCode == Keys.LWin)
                    {
                        Win = true;
                    }
                    else
                    {
                        result = OnKeyDown((Keys)vkCode);
                    }
                }
                else if (wParam == (IntPtr)Hooks.WM_KEYUP ||
                         wParam == (IntPtr)Hooks.WM_SYSKEYUP)
                {
                    int vkCode = Marshal.ReadInt32(lParam);
                    if ((Keys)vkCode == Keys.LControlKey ||
                        (Keys)vkCode == Keys.RControlKey)
                    {
                        Control = false;
                    }
                    else if ((Keys)vkCode == Keys.LShiftKey ||
                             (Keys)vkCode == Keys.RShiftKey)
                    {
                        Shift = false;
                    }
                    else if ((Keys)vkCode == Keys.RMenu ||
                             (Keys)vkCode == Keys.LMenu)
                    {
                        Alt = false;
                    }
                    else if ((Keys)vkCode == Keys.RWin ||
                             (Keys)vkCode == Keys.LWin)
                    {
                        Win = false;
                    }
                    else
                    {
                        result = OnKeyUp((Keys)vkCode);
                    }
                }
            }

            return(result ? Hooks.CallNextHookEx(hHook, nCode, wParam, lParam) : new IntPtr(1));
        }
Exemple #2
0
        private static IntPtr Filter(int nCode, IntPtr wParam, IntPtr lParam)
        {
            bool result = true;

            if (nCode >= 0)
            {
                Hooks.MouseHookStruct info = (Hooks.MouseHookStruct)Marshal.PtrToStructure(lParam, typeof(Hooks.MouseHookStruct));
                switch ((int)wParam)
                {
                case Hooks.WM_LBUTTONDOWN:
                    result = OnMouseDown(MouseButtons.Left);
                    break;

                case Hooks.WM_LBUTTONUP:
                    result = OnMouseUp(MouseButtons.Left);
                    break;

                case Hooks.WM_RBUTTONDOWN:
                    result = OnMouseDown(MouseButtons.Right);
                    break;

                case Hooks.WM_RBUTTONUP:
                    result = OnMouseUp(MouseButtons.Right);
                    break;

                case Hooks.WM_MBUTTONDOWN:
                    result = OnMouseDown(MouseButtons.Middle);
                    break;

                case Hooks.WM_MBUTTONUP:
                    result = OnMouseUp(MouseButtons.Middle);
                    break;

                case Hooks.WM_XBUTTONDOWN:
                    if (info.Data >> 16 == Hooks.XBUTTON1)
                    {
                        result = OnMouseDown(MouseButtons.XButton1);
                    }
                    else if (info.Data >> 16 == Hooks.XBUTTON2)
                    {
                        result = OnMouseDown(MouseButtons.XButton2);
                    }
                    break;

                case Hooks.WM_XBUTTONUP:
                    if (info.Data >> 16 == Hooks.XBUTTON1)
                    {
                        result = OnMouseUp(MouseButtons.XButton1);
                    }
                    else if (info.Data >> 16 == Hooks.XBUTTON2)
                    {
                        result = OnMouseUp(MouseButtons.XButton2);
                    }
                    break;

                case Hooks.WM_MOUSEMOVE:
                    result = OnMouseMove(new Point(info.Point.X, info.Point.Y));
                    break;

                case Hooks.WM_MOUSEWHEEL:
                    result = OnMouseWheel((info.Data >> 16) & 0xffff);
                    break;
                }
            }

            return(result ? Hooks.CallNextHookEx(hHook, nCode, wParam, lParam) : new IntPtr(1));
        }