Exemple #1
0
 public virtual void touchButtonDown(object sender, TouchpadEventArgs arg)
 {
     if (arg.touches == null)
     {
         upperDown = true;
     }
     else if (arg.touches.Length > 1)
     {
         multiDown = true;
     }
     else
     {
         if (Global.LowerRCOn[deviceNum] && (arg.touches[0].hwX > 1920 * 3 / 4) && (arg.touches[0].hwY > 960 * 3 / 4))
         {
             Mapping.MapClick(deviceNum, Mapping.Click.Right);
         }
         if (isLeft(arg.touches[0]))
         {
             leftDown = true;
         }
         else if (isRight(arg.touches[0]))
         {
             rightDown = true;
         }
     }
     dev.GetCurrentState(state);
     synthesizeMouseButtons();
 }
 public void touchesBegan(TouchpadEventArgs arg)
 {
     if (arg.touches.Length == 2)
     {
         horizontalRemainder = verticalRemainder = 0.0;
     }
 }
 public void touchesBegan(TouchpadEventArgs arg)
 {
     if (arg.touches.Length != 1)
     {
         return;
     }
     horizontalRemainder = verticalRemainder = 0.0;
     horizontalDirection = verticalDirection = Direction.Neutral;
 }
        public void touchesMoved(TouchpadEventArgs arg, bool dragging)
        {
            if ((arg.touches.Length != 2) || dragging)
            {
                return;
            }
            Touch lastT0 = arg.touches[0].previousTouch;
            Touch lastT1 = arg.touches[1].previousTouch;
            Touch T0 = arg.touches[0];
            Touch T1 = arg.touches[1];

            //mouse wheel 120 == 1 wheel click according to Windows API
            double lastMidX = (lastT0.hwX + lastT1.hwX) / 2d,
                lastMidY = (lastT0.hwY + lastT1.hwY) / 2d,
                currentMidX = (T0.hwX + T1.hwX) / 2d,
                currentMidY = (T0.hwY + T1.hwY) / 2d;
            double coefficient = Global.ScrollSensitivity[deviceNumber];
            // Adjust for touch distance: "standard" distance is 960 pixels, i.e. half the width.  Scroll farther if fingers are farther apart, and vice versa, in linear proportion.
            double touchXDistance = T1.hwX - T0.hwX, touchYDistance = T1.hwY - T0.hwY, touchDistance = Math.Sqrt(touchXDistance * touchXDistance + touchYDistance * touchYDistance);
            coefficient *= touchDistance / 960.0;

            // Collect rounding errors instead of losing motion.
            double xMotion = coefficient * (currentMidX - lastMidX);
            if (((xMotion > 0.0) && (horizontalRemainder > 0.0)) || ((xMotion < 0.0) && (horizontalRemainder < 0.0)))
            {
                xMotion += horizontalRemainder;
            }
            int xAction = (int)xMotion;
            horizontalRemainder = xMotion - xAction;

            double yMotion = coefficient * (lastMidY - currentMidY);
            if (((yMotion > 0.0) && (verticalRemainder > 0.0)) || ((yMotion < 0.0) && (verticalRemainder < 0.0)))
            {
                yMotion += verticalRemainder;
            }
            int yAction = (int)yMotion;
            verticalRemainder = yMotion - yAction;

            if ((yAction != 0) || (xAction != 0))
            {
                InputMethods.MouseWheel(yAction, xAction);
            }
        }
        public void touchesMoved(TouchpadEventArgs arg, bool dragging)
        {
            if ((!dragging && (arg.touches.Length != 1)) || (dragging && (arg.touches.Length < 1)))
            {
                return;
            }
            int deltaX, deltaY;
            if (arg.touches[0].touchID != lastTouchID)
            {
                deltaX = deltaY = 0;
                horizontalRemainder = verticalRemainder = 0.0;
                horizontalDirection = verticalDirection = Direction.Neutral;
                lastTouchID = arg.touches[0].touchID;
            }
            else if (Global.TouchpadJitterCompensation[deviceNumber])
            {
                // Often the DS4's internal jitter compensation kicks in and starts hiding changes, ironically creating jitter...

                if (dragging && (arg.touches.Length > 1))
                {
                    deltaX = arg.touches[1].deltaX;
                    deltaY = arg.touches[1].deltaY;
                }
                else
                {
                    deltaX = arg.touches[0].deltaX;
                    deltaY = arg.touches[0].deltaY;
                }
                // allow only very fine, slow motions, when changing direction, even from neutral
                // TODO maybe just consume it completely?
                if (deltaX <= -1)
                {
                    if (horizontalDirection != Direction.Negative)
                    {
                        deltaX = -1;
                        horizontalRemainder = 0.0;
                    }
                }
                else if (deltaX >= 1)
                {
                    if (horizontalDirection != Direction.Positive)
                    {
                        deltaX = 1;
                        horizontalRemainder = 0.0;
                    }
                }

                if (deltaY <= -1)
                {
                    if (verticalDirection != Direction.Negative)
                    {
                        deltaY = -1;
                        verticalRemainder = 0.0;
                    }
                }
                else if (deltaY >= 1)
                {
                    if (verticalDirection != Direction.Positive)
                    {
                        deltaY = 1;
                        verticalRemainder = 0.0;
                    }
                }
            }
            else
            {
                if (dragging && (arg.touches.Length > 1))
                {
                    deltaX = arg.touches[1].deltaX;
                    deltaY = arg.touches[1].deltaY;
                }
                else
                {
                    deltaX = arg.touches[0].deltaX;
                    deltaY = arg.touches[0].deltaY;
                }
            }

            double coefficient = Global.TouchSensitivity[deviceNumber] / 100.0;
            // Collect rounding errors instead of losing motion.
            double xMotion = coefficient * deltaX;
            if (xMotion > 0.0)
            {
                if (horizontalRemainder > 0.0)
                {
                    xMotion += horizontalRemainder;
                }
            }
            else if (xMotion < 0.0)
            {
                if (horizontalRemainder < 0.0)
                {
                    xMotion += horizontalRemainder;
                }
            }
            int xAction = (int)xMotion;
            horizontalRemainder = xMotion - xAction;

            double yMotion = coefficient * deltaY;
            if (yMotion > 0.0)
            {
                if (verticalRemainder > 0.0)
                {
                    yMotion += verticalRemainder;
                }
            }
            else if (yMotion < 0.0)
            {
                if (verticalRemainder < 0.0)
                {
                    yMotion += verticalRemainder;
                }
            }
            int yAction = (int)yMotion;
            verticalRemainder = yMotion - yAction;

            if ((yAction != 0) || (xAction != 0))
            {
                InputMethods.MoveCursorBy(xAction, yAction);
            }

            horizontalDirection = xMotion > 0.0 ? Direction.Positive : xMotion < 0.0 ? Direction.Negative : Direction.Neutral;
            verticalDirection = yMotion > 0.0 ? Direction.Positive : yMotion < 0.0 ? Direction.Negative : Direction.Neutral;
        }
        public void handleTouchpad(byte[] data, DS4State sensors, int touchPacketOffset = 0)
        {
            bool touchPadIsDown = sensors.TouchButton;
            if (!PacketChanged(data, touchPacketOffset) && (touchPadIsDown == lastTouchPadIsDown))
            {
                TouchUnchanged?.Invoke(this, EventArgs.Empty);
                return;
            }
            byte touchID1 = (byte)(data[0 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0x7F);
            byte touchID2 = (byte)(data[4 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0x7F);
            int currentX1 = data[1 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] + (data[2 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0xF) * 255;
            int currentY1 = ((data[2 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0xF0) >> 4) + data[3 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] * 16;
            int currentX2 = data[5 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] + (data[6 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0xF) * 255;
            int currentY2 = ((data[6 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0xF0) >> 4) + data[7 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] * 16;

            TouchpadEventArgs args;
            if (sensors.Touch1 || sensors.Touch2)
            {
                if ((sensors.Touch1 && !lastIsActive1) || (sensors.Touch2 && !lastIsActive2))
                {
                    if (TouchesBegan != null)
                    {
                        if (sensors.Touch1 && sensors.Touch2)
                        {
                            args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, new Touch(currentX1, currentY1, touchID1), new Touch(currentX2, currentY2, touchID2));
                        }
                        else if (sensors.Touch1)
                        {
                            args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, new Touch(currentX1, currentY1, touchID1));
                        }
                        else
                        {
                            args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, new Touch(currentX2, currentY2, touchID2));
                        }

                        TouchesBegan(this, args);
                    }
                }
                else if ((sensors.Touch1 == lastIsActive1) && (sensors.Touch2 == lastIsActive2) && (TouchesMoved != null))
                {
                    Touch tPrev, t0, t1;

                    if (sensors.Touch1 && sensors.Touch2)
                    {
                        tPrev = new Touch(lastTouchPadX1, lastTouchPadY1, lastTouchID1);
                        t0 = new Touch(currentX1, currentY1, touchID1, tPrev);
                        tPrev = new Touch(lastTouchPadX2, lastTouchPadY2, lastTouchID2);
                        t1 = new Touch(currentX2, currentY2, touchID2, tPrev);
                    }
                    else if (sensors.Touch1)
                    {
                        tPrev = new Touch(lastTouchPadX1, lastTouchPadY1, lastTouchID1);
                        t0 = new Touch(currentX1, currentY1, touchID1, tPrev);
                        t1 = null;
                    }
                    else
                    {
                        tPrev = new Touch(lastTouchPadX2, lastTouchPadY2, lastTouchID2);
                        t0 = new Touch(currentX2, currentY2, touchID2, tPrev);
                        t1 = null;
                    }
                    args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, t0, t1);

                    TouchesMoved(this, args);
                }

                if (!lastTouchPadIsDown && touchPadIsDown && (TouchButtonDown != null))
                {
                    if (sensors.Touch1 && sensors.Touch2)
                    {
                        args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, new Touch(currentX1, currentY1, touchID1), new Touch(currentX2, currentY2, touchID2));
                    }
                    else if (sensors.Touch1)
                    {
                        args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, new Touch(currentX1, currentY1, touchID1));
                    }
                    else
                    {
                        args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, new Touch(currentX2, currentY2, touchID2));
                    }

                    TouchButtonDown(this, args);
                }
                else if (lastTouchPadIsDown && !touchPadIsDown && (TouchButtonUp != null))
                {
                    if (sensors.Touch1 && sensors.Touch2)
                    {
                        args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, new Touch(currentX1, currentY1, touchID1), new Touch(currentX2, currentY2, touchID2));
                    }
                    else if (sensors.Touch1)
                    {
                        args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, new Touch(currentX1, currentY1, touchID1));
                    }
                    else
                    {
                        args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, new Touch(currentX2, currentY2, touchID2));
                    }

                    TouchButtonUp(this, args);
                }

                if (sensors.Touch1)
                {
                    lastTouchPadX1 = currentX1;
                    lastTouchPadY1 = currentY1;
                }
                if (sensors.Touch2)
                {
                    lastTouchPadX2 = currentX2;
                    lastTouchPadY2 = currentY2;
                }
                lastTouchPadIsDown = touchPadIsDown;
            }
            else
            {
                if (touchPadIsDown && !lastTouchPadIsDown)
                {
                    TouchButtonDown?.Invoke(this, new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, null));
                }
                else if (!touchPadIsDown && lastTouchPadIsDown)
                {
                    TouchButtonUp?.Invoke(this, new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, null));
                }

                if ((lastIsActive1 || lastIsActive2) && (TouchesEnded != null))
                {
                    if (lastIsActive1 && lastIsActive2)
                    {
                        args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, new Touch(lastTouchPadX1, lastTouchPadY1, touchID1), new Touch(lastTouchPadX2, lastTouchPadY2, touchID2));
                    }
                    else if (lastIsActive1)
                    {
                        args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, new Touch(lastTouchPadX1, lastTouchPadY1, touchID1));
                    }
                    else
                    {
                        args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, new Touch(lastTouchPadX2, lastTouchPadY2, touchID2));
                    }

                    TouchesEnded(this, args);
                }
            }

            lastIsActive1 = sensors.Touch1;
            lastIsActive2 = sensors.Touch2;
            lastTouchID1 = touchID1;
            lastTouchID2 = touchID2;
            lastTouchPadIsDown = touchPadIsDown;
        }
Exemple #7
0
 public virtual void touchesMoved(object sender, TouchpadEventArgs arg)
 {
     if (!Global.UseTPforControls[deviceNum])
     {
         cursor.touchesMoved(arg, dragging || dragging2);
         wheel.touchesMoved(arg, dragging || dragging2);
     }
     else
     {
         if (!(swipeUp || swipeDown || swipeLeft || swipeRight) && (arg.touches.Length == 1))
         {
             if (arg.touches[0].hwX - firstTouch.hwX > 400)
             {
                 swipeRight = true;
             }
             if (arg.touches[0].hwX - firstTouch.hwX < -400)
             {
                 swipeLeft = true;
             }
             if (arg.touches[0].hwY - firstTouch.hwY > 300)
             {
                 swipeDown = true;
             }
             if (arg.touches[0].hwY - firstTouch.hwY < -300)
             {
                 swipeUp = true;
             }
         }
         swipeUpB = (byte)Math.Min(255, Math.Max(0, (firstTouch.hwY - arg.touches[0].hwY) * 1.5f));
         swipeDownB = (byte)Math.Min(255, Math.Max(0, (arg.touches[0].hwY - firstTouch.hwY) * 1.5f));
         swipeLeftB = (byte)Math.Min(255, Math.Max(0, firstTouch.hwX - arg.touches[0].hwX));
         swipeRightB = (byte)Math.Min(255, Math.Max(0, arg.touches[0].hwX - firstTouch.hwX));
     }
     if ((Math.Abs(firstTouch.hwY - arg.touches[0].hwY) < 50) && (arg.touches.Length == 2))
     {
         if ((arg.touches[0].hwX - firstTouch.hwX > 200) && !slideleft)
         {
             slideright = true;
         }
         else if ((firstTouch.hwX - arg.touches[0].hwX > 200) && !slideright)
         {
             slideleft = true;
         }
     }
     dev.GetCurrentState(state);
     synthesizeMouseButtons();
 }
Exemple #8
0
 public virtual void touchesEnded(object sender, TouchpadEventArgs arg)
 {
     slideright = slideleft = false;
     swipeUp = swipeDown = swipeLeft = swipeRight = false;
     swipeUpB = swipeDownB = swipeLeftB = swipeRightB = 0;
     if ((Global.TapSensitivity[deviceNum] != 0) && !Global.UseTPforControls[deviceNum])
     {
         if (secondtouchbegin)
         {
             tappedOnce = false;
             secondtouchbegin = false;
         }
         DateTime test = arg.timeStamp;
         if ((test <= pastTime + TimeSpan.FromMilliseconds((double)Global.TapSensitivity[deviceNum] * 2)) && !arg.touchButtonPressed && !tappedOnce)
         {
             if ((Math.Abs(firstTouch.hwX - arg.touches[0].hwX) < 10) && (Math.Abs(firstTouch.hwY - arg.touches[0].hwY) < 10))
             {
                 if (Global.DoubleTap[deviceNum])
                 {
                     tappedOnce = true;
                     firstTap = arg.timeStamp;
                     TimeofEnd = DateTime.Now; //since arg can't be used in synthesizeMouseButtons
                 }
                 else
                 {
                     Mapping.MapClick(deviceNum, Mapping.Click.Left); //this way no delay if disabled
                 }
             }
         }
     }
     dev.GetCurrentState(state);
     synthesizeMouseButtons();
 }
Exemple #9
0
 public virtual void touchesBegan(object sender, TouchpadEventArgs arg)
 {
     if (!Global.UseTPforControls[deviceNum])
     {
         cursor.touchesBegan(arg);
         wheel.touchesBegan(arg);
     }
     pastTime = arg.timeStamp;
     firstTouch = arg.touches[0];
     if (Global.DoubleTap[deviceNum])
     {
         DateTime test = arg.timeStamp;
         if ((test <= firstTap + TimeSpan.FromMilliseconds(Global.TapSensitivity[deviceNum] * 1.5)) && !arg.touchButtonPressed)
         {
             secondtouchbegin = true;
         }
     }
     dev.GetCurrentState(state);
     synthesizeMouseButtons();
 }
Exemple #10
0
 public virtual void touchButtonUp(object sender, TouchpadEventArgs arg)
 {
     upperDown = leftDown = rightDown = multiDown = false;
     dev.SetRumble(0, 0);
     dev.GetCurrentState(state);
     if (state.Touch1 || state.Touch2)
     {
         synthesizeMouseButtons();
     }
 }