Пример #1
0
        private void mouseHook_OnMouseMessage(object sender, MouseHook.MouseEventArgs32 e)
        {
            switch (e.Message)
            {
            case User32_MouseHook.MouseMessages.WM_LBUTTONDOWN:
                _lBtnDown = true;
                break;

            case User32_MouseHook.MouseMessages.WM_LBUTTONUP:
                _lBtnDown = false;
                break;

            case User32_MouseHook.MouseMessages.WM_MOUSEMOVE:
                OnMouseMove(e);
                break;

            case User32_MouseHook.MouseMessages.WM_MOUSEWHEEL:
                break;

            case User32_MouseHook.MouseMessages.WM_RBUTTONDOWN:
                _rBtnDown = true;
                break;

            case User32_MouseHook.MouseMessages.WM_RBUTTONUP:
                _rBtnDown = false;
                break;

            default:
                break;
            }
        }
Пример #2
0
        private void OnMouseMove(MouseHook.MouseEventArgs32 e)
        {
            User32.POINT ptCurr = e.MessageData.pt;
            if (ptCurr.Equals(_prev))
            {
                //Debug.WriteLine("SKIP => Mouse Position:{0}", _prev);
                return; //already been there
            }

            User32.POINT ptPrev = _prev;
            _prev = e.MessageData.pt;

            if (IsButtonDown || _screens.Count == 1 || !MouseHook.Hook.Enabled)
            {
                return; //ignore dragging or if one sceen only or if not enabled
            }
            int screenSrcIndex = ScreenFromPoint(ptPrev);

            if (screenSrcIndex < 0) //point out of screen
            {
                return;
            }

            User32.POINT ptCorrected = CorrectIntoOtherScreenProportionally(ptPrev, ptCurr, screenSrcIndex);
            if (ptCorrected.X != 0 || ptCorrected.Y != 0)
            {
                _prev = ptCorrected; //already handled
                User32.SetCursorPos(ptCorrected.X, ptCorrected.Y);
            }
        }