protected virtual void CheckForHotkeys(int deviceID, DS4State cState, DS4State pState) { DS4Device d = DS4Controllers[deviceID]; if ((!pState.PS || !pState.Options) && cState.PS && cState.Options) { if (!d.Charging) { d.DisconnectBT(); InputMethods.performKeyRelease(Global.getCustomKey(0, DS4Controls.PS)); string[] skeys = Global.getCustomMacro(0, DS4Controls.PS).Split('/'); ushort[] keys = new ushort[skeys.Length]; for (int i = 0; i < keys.Length; i++) { keys[i] = ushort.Parse(skeys[i]); InputMethods.performKeyRelease(keys[i]); } d = null; } } if (!Global.getUseTPforControls(deviceID) && cState.Touch1 && pState.PS) { if (Global.getTouchSensitivity(deviceID) > 0 && touchreleased[deviceID]) { oldtouchvalue[deviceID] = Global.getTouchSensitivity(deviceID); oldscrollvalue[deviceID] = Global.getScrollSensitivity(deviceID); Global.setTouchSensitivity(deviceID, 0); Global.setScrollSensitivity(deviceID, 0); LogDebug(Global.getTouchSensitivity(deviceID) > 0 ? Properties.Resources.TouchpadMovementOn : Properties.Resources.TouchpadMovementOff); Log.LogToTray(Global.getTouchSensitivity(deviceID) > 0 ? Properties.Resources.TouchpadMovementOn : Properties.Resources.TouchpadMovementOff); touchreleased[deviceID] = false; } else if (touchreleased[deviceID]) { Global.setTouchSensitivity(deviceID, oldtouchvalue[deviceID]); Global.setScrollSensitivity(deviceID, oldscrollvalue[deviceID]); LogDebug(Global.getTouchSensitivity(deviceID) > 0 ? Properties.Resources.TouchpadMovementOn : Properties.Resources.TouchpadMovementOff); Log.LogToTray(Global.getTouchSensitivity(deviceID) > 0 ? Properties.Resources.TouchpadMovementOn : Properties.Resources.TouchpadMovementOff); touchreleased[deviceID] = false; } } else { touchreleased[deviceID] = true; } }
public void touchesMoved(TouchpadEventArgs arg) { if (arg.touches.Length != 2) { 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.getScrollSensitivity(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) { 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 * (lastMidY - currentMidY); 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.MouseWheel(yAction, xAction); } }
public void touchesMoved(TouchpadEventArgs arg) { if (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.getTouchpadJitterCompensation(deviceNumber)) { // Often the DS4's internal jitter compensation kicks in and starts hiding changes, ironically creating jitter... 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 { deltaX = arg.touches[0].deltaX; deltaY = arg.touches[0].deltaY; } double coefficient = Global.getTouchSensitivity(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; }