public void touchesBegan(TouchpadEventArgs arg) { if (arg.touches.Length == 1) { 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; // Express coefficient as a ratio double coefficient = Global.ScrollSensitivity[deviceNumber] / 100.0; // 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) { yAction = yAction < 0 ? yAction * -1 * Global.outputKBMMapping.WHEEL_TICK_DOWN : yAction * Global.outputKBMMapping.WHEEL_TICK_UP; xAction = xAction < 0 ? xAction * -1 * Global.outputKBMMapping.WHEEL_TICK_DOWN : xAction * Global.outputKBMMapping.WHEEL_TICK_UP; Global.outputKBMHandler.PerformMouseWheelEvent(yAction, xAction); } }
public virtual void touchButtonUp(object sender, TouchpadEventArgs arg) { pushed = DS4Controls.None; upperDown = leftDown = rightDown = multiDown = false; dev.setRumble(0, 0); dev.getCurrentState(s); if (s.Touch1 || s.Touch2) { synthesizeMouseButtons(); } }
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(s); synthesizeMouseButtons(); }
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((double)Global.TapSensitivity[deviceNum] * 1.5)) && !arg.touchButtonPressed) { secondtouchbegin = true; } } dev.getCurrentState(s); synthesizeMouseButtons(); }
public virtual void touchesEnded(object sender, TouchpadEventArgs arg) { slideright = slideleft = false; swipeUp = swipeDown = swipeLeft = swipeRight = false; swipeUpB = swipeDownB = swipeLeftB = swipeRightB = 0; byte tapSensitivity = Global.TapSensitivity[deviceNum]; if (tapSensitivity != 0 && !Global.UseTPforControls[deviceNum]) { if (secondtouchbegin) { tappedOnce = false; secondtouchbegin = false; } DateTime test = arg.timeStamp; if (test <= (pastTime + TimeSpan.FromMilliseconds((double)tapSensitivity * 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 } } } } s = dev.getCurrentStateRef(); synthesizeMouseButtons(); }
private void Controller_TouchpadMoved(TouchpadEventArgs e) { // Convert all touchpad touches and raise event InputTouch[] inputTouch = new InputTouch[e.touches.Length]; for (int i = 0; i < inputTouch.Length; i++) { inputTouch[i] = new InputTouch() { DeltaX = e.touches[i].deltaX, DeltaY = e.touches[i].deltaY, AbsX = e.touches[i].hwX, AbsY = e.touches[i].hwY, }; } OnTouchpadMoved(new InputTouchpadEventArgs() { touches = inputTouch }); }
public void handleTouchpad(byte[] data, DS4State sensors, int touchPacketOffset = 0) { bool touchPadIsDown = sensors.TouchButton; if (!PacketChanged(data, touchPacketOffset) && touchPadIsDown == lastTouchPadIsDown) { if (TouchUnchanged != null) TouchUnchanged(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) { if (TouchButtonDown != null) TouchButtonDown(this, new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, null, null)); } else if (!touchPadIsDown && lastTouchPadIsDown) { if (TouchButtonUp != null) TouchButtonUp(this, new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, null, 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; }
private static void DS4TouchpadButtonUp(object sender, TouchpadEventArgs args) { if (!Settings.Default.EnableTouchpad) return; // Ignore touchpad if disabled during mouselook // Ignore touchpad if disabled during mouselook if (Settings.Default.MemoryTouchpadCursorOnly && WoWReader.IsAttached && WoWReader.GameState && WoWReader.MouselookState) return; switch (Settings.Default.TouchpadMode) { case 0: WoWInput.SendMouseUp(args.touches.Last().hwX < (1920/2) ? MouseButton.Left : MouseButton.Right); break; case 1: WoWInput.SendKeyUp(args.touches.Last().hwX < (1920/2) ? BindManager.GetKey(GamepadButton.CenterLeft) : BindManager.GetKey(GamepadButton.CenterRight)); break; } }
public virtual void touchesMoved(object sender, TouchpadEventArgs arg) { s = dev.getCurrentStateRef(); if (Global.getUseTPforControls(deviceNum) == false) { int[] disArray = Global.getTouchDisInvertTriggers(deviceNum); tempBool = true; for (int i = 0, arlen = disArray.Length; tempBool && i < arlen; i++) { if (getDS4ControlsByName(disArray[i]) == false) { tempBool = false; } } cursor.touchesMoved(arg, dragging || dragging2, tempBool); 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; } } synthesizeMouseButtons(); }
public virtual void touchesEnded(object sender, TouchpadEventArgs arg) { s = dev.getCurrentStateRef(); slideright = slideleft = false; swipeUp = swipeDown = swipeLeft = swipeRight = false; swipeUpB = swipeDownB = swipeLeftB = swipeRightB = 0; byte tapSensitivity = Global.getTapSensitivity(deviceNum); if (tapSensitivity != 0 && !Global.getUseTPforControls(deviceNum)) { if (secondtouchbegin) { tappedOnce = false; secondtouchbegin = false; } DateTime test = arg.timeStamp; if (test <= (pastTime + TimeSpan.FromMilliseconds((double)tapSensitivity * 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.getDoubleTap(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 } } } } else { if (Global.getUseTPforControls(deviceNum) == false) { int[] disArray = Global.getTouchDisInvertTriggers(deviceNum); tempBool = true; for (int i = 0, arlen = disArray.Length; tempBool && i < arlen; i++) { if (getDS4ControlsByName(disArray[i]) == false) { tempBool = false; } } if (Global.getTrackballMode(deviceNum)) { if (!trackballActive) { double currentWeight = 1.0; double finalWeight = 0.0; double x_out = 0.0, y_out = 0.0; int idx = -1; for (int i = 0; i < TRACKBALL_BUFFER_LEN && idx != trackballBufferHead; i++) { idx = (trackballBufferTail - i - 1 + TRACKBALL_BUFFER_LEN) % TRACKBALL_BUFFER_LEN; x_out += trackballXBuffer[idx] * currentWeight; y_out += trackballYBuffer[idx] * currentWeight; finalWeight += currentWeight; currentWeight *= 1.0; } x_out /= finalWeight; trackballXVel = x_out; y_out /= finalWeight; trackballYVel = y_out; trackballActive = true; } double tempAngle = Math.Atan2(-trackballYVel, trackballXVel); double normX = Math.Abs(Math.Cos(tempAngle)); double normY = Math.Abs(Math.Sin(tempAngle)); int signX = Math.Sign(trackballXVel); int signY = Math.Sign(trackballYVel); double trackXvDecay = Math.Min(Math.Abs(trackballXVel), trackballAccel * s.elapsedTime * normX); double trackYvDecay = Math.Min(Math.Abs(trackballYVel), trackballAccel * s.elapsedTime * normY); double xVNew = trackballXVel - (trackXvDecay * signX); double yVNew = trackballYVel - (trackYvDecay * signY); double xMotion = (xVNew * s.elapsedTime) / TRACKBALL_SCALE; double yMotion = (yVNew * s.elapsedTime) / TRACKBALL_SCALE; if (xMotion != 0.0) { xMotion += trackballDXRemain; } else { trackballDXRemain = 0.0; } int dx = (int)xMotion; trackballDXRemain = xMotion - dx; if (yMotion != 0.0) { yMotion += trackballDYRemain; } else { trackballDYRemain = 0.0; } int dy = (int)yMotion; trackballDYRemain = yMotion - dy; trackballXVel = xVNew; trackballYVel = yVNew; if (dx == 0 && dy == 0) { trackballActive = false; } else { cursor.TouchMoveCursor(dx, dy, tempBool); } } } } synthesizeMouseButtons(); }
public virtual void touchesMoved(object sender, TouchpadEventArgs arg) { s = dev.getCurrentStateRef(); if (Global.getUseTPforControls(deviceNum) == false) { int[] disArray = Global.getTouchDisInvertTriggers(deviceNum); tempBool = true; for (int i = 0, arlen = disArray.Length; tempBool && i < arlen; i++) { if (getDS4ControlsByName(disArray[i]) == false) { tempBool = false; } } if (Global.getTrackballMode(deviceNum)) { int iIndex = trackballBufferTail; trackballXBuffer[iIndex] = (arg.touches[0].deltaX * TRACKBALL_SCALE) / dev.getCurrentStateRef().elapsedTime; trackballYBuffer[iIndex] = (arg.touches[0].deltaY * TRACKBALL_SCALE) / dev.getCurrentStateRef().elapsedTime; trackballBufferTail = (iIndex + 1) % TRACKBALL_BUFFER_LEN; if (trackballBufferHead == trackballBufferTail) { trackballBufferHead = (trackballBufferHead + 1) % TRACKBALL_BUFFER_LEN; } } cursor.touchesMoved(arg, dragging || dragging2, tempBool); 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; } } synthesizeMouseButtons(); }
public void touchesMoved(TouchpadEventArgs arg, bool dragging, bool disableInvert = false) { int touchesLen = arg.touches.Length; if ((!dragging && touchesLen != 1) || (dragging && touchesLen < 1)) { return; } int deltaX = 0, deltaY = 0; if (arg.touches[0].touchID != lastTouchID) { deltaX = deltaY = 0; horizontalRemainder = verticalRemainder = 0.0; horizontalDirection = verticalDirection = Direction.Neutral; lastTouchID = arg.touches[0].touchID; } else { if (dragging && touchesLen > 1) { deltaX = arg.touches[1].deltaX; deltaY = arg.touches[1].deltaY; } else { deltaX = arg.touches[0].deltaX; deltaY = arg.touches[0].deltaY; } } double tempAngle = Math.Atan2(-deltaY, deltaX); double normX = Math.Abs(Math.Cos(tempAngle)); double normY = Math.Abs(Math.Sin(tempAngle)); int signX = Math.Sign(deltaX); int signY = Math.Sign(deltaY); double coefficient = Global.getTouchSensitivity(deviceNumber) * 0.01; bool jitterCompenstation = Global.getTouchpadJitterCompensation(deviceNumber); double xMotion = deltaX != 0 ? coefficient * deltaX + (normX * (TOUCHPAD_MOUSE_OFFSET * signX)) : 0.0; double yMotion = deltaY != 0 ? coefficient * deltaY + (normY * (TOUCHPAD_MOUSE_OFFSET * signY)) : 0.0; if (jitterCompenstation) { double absX = Math.Abs(xMotion); if (absX <= normX * 0.4) { xMotion = signX * Math.Pow(absX / 0.4f, 1.44) * 0.4; } double absY = Math.Abs(yMotion); if (absY <= normY * 0.4) { yMotion = signY * Math.Pow(absY / 0.4f, 1.44) * 0.4; } } // Collect rounding errors instead of losing motion. if (xMotion > 0.0 && horizontalRemainder > 0.0) { xMotion += horizontalRemainder; } else if (xMotion < 0.0 && horizontalRemainder < 0.0) { xMotion += horizontalRemainder; } int xAction = (int)xMotion; horizontalRemainder = xMotion - xAction; if (yMotion > 0.0 && verticalRemainder > 0.0) { yMotion += verticalRemainder; } else if (yMotion < 0.0 && verticalRemainder < 0.0) { yMotion += verticalRemainder; } int yAction = (int)yMotion; verticalRemainder = yMotion - yAction; if (disableInvert == false) { int touchpadInvert = tempInt = Global.getTouchpadInvert(deviceNumber); if ((touchpadInvert & 0x02) == 2) { xAction *= -1; } if ((touchpadInvert & 0x01) == 1) { yAction *= -1; } } 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 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; }
private static void DS4TouchpadMoved(object sender, TouchpadEventArgs args) { if (!Settings.Default.EnableTouchpad) return; // Ignore touchpad if disabled during mouselook if (Settings.Default.MemoryTouchpadCursorOnly && WoWReader.IsAttached && WoWReader.GameState && WoWReader.MouselookState) return; var x = args.touches.Last().deltaX; var y = args.touches.Last().deltaY; var cur = Cursor.Position; cur.X += x; cur.Y += y; Cursor.Position = cur; }
public void handleTouchpad(byte[] data, DS4State sensors, int touchPacketOffset = 0) { PreTouchProcess?.Invoke(this, EventArgs.Empty); bool touchPadIsDown = sensors.TouchButton; if (!PacketChanged(data, touchPacketOffset) && touchPadIsDown == lastTouchPadIsDown) { if (TouchUnchanged != null) { TouchUnchanged(this, EventArgs.Empty); } return; } Array.Copy(data, TOUCHPAD_DATA_OFFSET + touchPacketOffset, previousPacket, 0, 8); byte touchID1 = (byte)(data[0 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0x7F); byte touchID2 = (byte)(data[4 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0x7F); int currentX1 = ((data[2 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0x0F) << 8) | data[1 + TOUCHPAD_DATA_OFFSET + touchPacketOffset]; int currentY1 = (data[3 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] << 4) | ((data[2 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0xF0) >> 4); int currentX2 = ((data[6 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0x0F) << 8) | data[5 + TOUCHPAD_DATA_OFFSET + touchPacketOffset]; int currentY2 = (data[7 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] << 4) | ((data[6 + TOUCHPAD_DATA_OFFSET + touchPacketOffset] & 0xF0) >> 4); TouchpadEventArgs args; if (sensors.Touch1 || sensors.Touch2) { if ((sensors.Touch1 && !lastIsActive1) || (sensors.Touch2 && !lastIsActive2)) { if (TouchesBegan != null) { if (sensors.Touch1 && sensors.Touch2) { t0.populate(currentX1, currentY1, touchID1); t1.populate(currentX2, currentY2, touchID2); args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, t0, t1); } else if (sensors.Touch1) { t0.populate(currentX1, currentY1, touchID1); args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, t0); } else { t0.populate(currentX2, currentY2, touchID2); args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, t0); } TouchesBegan(this, args); } } else if (sensors.Touch1 == lastIsActive1 && sensors.Touch2 == lastIsActive2 && TouchesMoved != null) { Touch currentT0, currentT1; if (sensors.Touch1 && sensors.Touch2) { tPrev0.populate(lastTouchPadX1, lastTouchPadY1, lastTouchID1); t0.populate(currentX1, currentY1, touchID1, tPrev0); currentT0 = t0; tPrev1.populate(lastTouchPadX2, lastTouchPadY2, lastTouchID2); t1.populate(currentX2, currentY2, touchID2, tPrev1); currentT1 = t1; } else if (sensors.Touch1) { tPrev0.populate(lastTouchPadX1, lastTouchPadY1, lastTouchID1); t0.populate(currentX1, currentY1, touchID1, tPrev0); currentT0 = t0; currentT1 = null; } else { tPrev0.populate(lastTouchPadX2, lastTouchPadY2, lastTouchID2); t0.populate(currentX2, currentY2, touchID2, tPrev0); currentT0 = t0; currentT1 = null; } args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, currentT0, currentT1); TouchesMoved(this, args); } if (!lastTouchPadIsDown && touchPadIsDown && TouchButtonDown != null) { if (sensors.Touch1 && sensors.Touch2) { t0.populate(currentX1, currentY1, touchID1); t1.populate(currentX2, currentY2, touchID2); args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, t0, t1); } else if (sensors.Touch1) { t0.populate(currentX1, currentY1, touchID1); args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, t0); } else { t0.populate(currentX2, currentY2, touchID2); args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, t0); } TouchButtonDown(this, args); } else if (lastTouchPadIsDown && !touchPadIsDown && TouchButtonUp != null) { if (sensors.Touch1 && sensors.Touch2) { t0.populate(currentX1, currentY1, touchID1); t1.populate(currentX2, currentY2, touchID2); args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, t0, t1); } else if (sensors.Touch1) { t0.populate(currentX1, currentY1, touchID1); args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, t0); } else { t0.populate(currentX2, currentY2, touchID2); args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, t0); } TouchButtonUp(this, args); } if (sensors.Touch1) { lastTouchPadX1 = currentX1; lastTouchPadY1 = currentY1; } if (sensors.Touch2) { lastTouchPadX2 = currentX2; lastTouchPadY2 = currentY2; } lastTouchPadIsDown = touchPadIsDown; } else { if (touchPadIsDown && !lastTouchPadIsDown) { if (TouchButtonDown != null) { TouchButtonDown(this, new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, null, null)); } } else if (!touchPadIsDown && lastTouchPadIsDown) { if (TouchButtonUp != null) { TouchButtonUp(this, new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, null, null)); } } if ((lastIsActive1 || lastIsActive2) && TouchesEnded != null) { if (lastIsActive1 && lastIsActive2) { t0.populate(lastTouchPadX1, lastTouchPadY1, touchID1); t1.populate(lastTouchPadX2, lastTouchPadY2, touchID2); args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, t0, t1); } else if (lastIsActive1) { t0.populate(lastTouchPadX1, lastTouchPadY1, touchID1); args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, t0); } else { t0.populate(lastTouchPadX2, lastTouchPadY2, touchID2); args = new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, t0); } TouchesEnded(this, args); } } lastIsActive1 = sensors.Touch1; lastIsActive2 = sensors.Touch2; lastTouchID1 = touchID1; lastTouchID2 = touchID2; lastTouchPadIsDown = touchPadIsDown; }
public void handleTouchpad(byte[] data, DS4State sensors, int touchPacketOffset = 0) { bool touchPadIsDown = sensors.TouchButton; if (!PacketChanged(data, touchPacketOffset) && touchPadIsDown == lastTouchPadIsDown) { if (TouchUnchanged != null) { TouchUnchanged(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) { if (TouchButtonDown != null) { TouchButtonDown(this, new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, null, null)); } } else if (!touchPadIsDown && lastTouchPadIsDown) { if (TouchButtonUp != null) { TouchButtonUp(this, new TouchpadEventArgs(sensors.ReportTimeStamp, sensors.TouchButton, null, 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; }
private void Touchpad_TouchesMoved(object sender, TouchpadEventArgs e) { TouchpadMoved(e); }