Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
        private int CalcProportionalY(User32.POINT ptCurr, Rect rFrom, Rect rTo, User32.POINT delta)
        {
            double srcRatioFromTop = (ptCurr.Y - rFrom.Top) / rFrom.Height;
            double dstY            = rTo.Top + srcRatioFromTop * rTo.Height;

            Debug.WriteLine("SrcRatio: {0:0.00} DstHeight:{1:0.0} DstY: {2:0.0}", srcRatioFromTop, rTo.Height, dstY);

            return((int)dstY);
        }
Exemplo n.º 3
0
 private int ScreenFromPoint(User32.POINT pt)
 {
     for (int i = 0; i < _screens.Count; i++)
     {
         if (_screens[i].DeviceBounds.Contains(pt.X, pt.Y))
         {
             return(i);
         }
     }
     ;
     return(-1);
 }
Exemplo n.º 4
0
        private int CorrectYIfNeeded(User32.POINT ptCurr, Rect rFrom, Rect rTo, User32.POINT delta)
        {
            if (ptCurr.Y > rTo.Top && ptCurr.Y < rTo.Bottom)
            {
                return(ptCurr.Y + delta.Y); //no correction needed
            }
            const int offsetY = 80;
            int       y       = (int)rTo.Top + offsetY;

            if (ptCurr.Y >= rTo.Bottom)
            {
                y = (int)(rTo.Bottom - offsetY);
            }

            return(y);
        }
Exemplo n.º 5
0
        //if screens are different height - move mouse vertical proportionally to border
        private User32.POINT CorrectIntoOtherScreenProportionally(User32.POINT ptPrev, User32.POINT ptCurr, int screenSrcIndex)
        {
            User32.POINT delta = ptCurr - ptPrev;
            Rect         rFrom = _screens[screenSrcIndex].DeviceBounds;
            Rect         rTo;

            int maxDistanceFromBorder = 1 + Math.Abs(delta.X);

            if (Math.Abs(ptCurr.X - _screens[screenSrcIndex].DeviceBounds.Left) < maxDistanceFromBorder) //close to left side
            {
                if (screenSrcIndex == 0 || delta.X >= 0)                                                 //left most or move away
                {
                    return(new User32.POINT());
                }
                rTo = _screens[screenSrcIndex - 1].DeviceBounds;
                Debug.WriteLine("LEFT => Mouse Position:{0} Delta:{1}", ptCurr, delta);
            }
            else if (Math.Abs(ptCurr.X - _screens[screenSrcIndex].DeviceBounds.Right) < maxDistanceFromBorder) //close to right side
            {
                if (screenSrcIndex == _screens.Count - 1 || delta.X <= 0)                                      //right most or move away
                {
                    return(new User32.POINT());
                }
                rTo = _screens[screenSrcIndex + 1].DeviceBounds;
                Debug.WriteLine("RIGHT => Mouse Position:{0} Delta:{1}", ptCurr, delta);
            }
            else
            {
                //Debug.WriteLine("MIDDLE => Mouse Position:{0} Delta:{1}", ptCurr, delta);
                return(new User32.POINT());
            }

            int dstY = CalcProportionalY(ptCurr, rFrom, rTo, delta);

            //int dstY = CorrectYIfNeeded(ptCurr, rFrom, rTo, delta);

            User32.POINT corrected = new User32.POINT(ptCurr.X + delta.X, dstY);
            Debug.WriteLine("Corrected Mouse Position: {0} Delta:{1}", corrected, delta);
            return(corrected);
        }