Esempio n. 1
0
        protected virtual bool OnKeyboardEvent(HookEventArgs args)
        {
            if (args == null)
            {
                return(false);
            }

            WM  wParam   = (WM)args.wParam.ToInt32();
            var hookInfo = Marshal.PtrToStructure <KBDLLHOOKSTRUCT>(args.lParam);
            var key      = (Keys)hookInfo.vkCode;

            bool alt     = IsKeyPressed(Keys.Menu);
            bool control = IsKeyPressed(Keys.ControlKey);

            return(_keyboadHandler.HandleKey(_handler, new KeyboardParam(wParam == WM.KEYUP, alt, control, key)));
        }
Esempio n. 2
0
        protected virtual bool OnMouseEvent(HookEventArgs args)
        {
            if (args == null)
            {
                return(false);
            }

            WM wParam = (WM)args.wParam.ToInt32();

            switch (wParam)
            {
            case WM.MOUSEMOVE:
                if (_dragWindowInfo != null && _dragWindowInfo.DragInitiated)
                {
                    POINT cursorPos = new POINT();
                    if (GetCurrentCursorLocation(args.lParam, ref cursorPos))
                    {
                        var ptDelta     = new POINT(cursorPos.x - _dragWindowInfo.DragPoint.x, cursorPos.y - _dragWindowInfo.DragPoint.y);
                        var newLocation = new POINT(_dragWindowInfo.DragWindowLocation.x + ptDelta.x, _dragWindowInfo.DragWindowLocation.y + ptDelta.y);
                        OnMouseMove(newLocation.x, newLocation.y);

                        return(false);
                    }
                }
                break;

            // button up messages
            case WM.LBUTTONUP:
                if (_dragWindowInfo != null && _dragWindowInfo.DragInitiated)
                {
                    OnLeftButtonUp();
                }
                break;
            }

            return(false);
        }