public void touchesEnded(object sender, TouchpadEventArgs arg) { if (Global.getTapSensitivity(deviceNum) != 0) { DateTime test = DateTime.Now; if (test <= (pastTime + TimeSpan.FromMilliseconds((double)Global.getTapSensitivity(deviceNum) * 2)) && !arg.touchButtonPressed) { if (Math.Abs(firstTouch.hwX - arg.touches[0].hwX) < 10 && Math.Abs(firstTouch.hwY - arg.touches[0].hwY) < 10) { performLeftClick(); } } } }
public void touchButtonUp(object sender, TouchpadEventArgs arg) { if (arg.touches == null) { //No touches, finger on upper portion of touchpad mapTouchPad(DS4Controls.TouchUpper, true); } else if (arg.touches.Length > 1) { mapTouchPad(DS4Controls.TouchMulti, true); } else if (!rightClick && arg.touches.Length == 1 && !mapTouchPad(DS4Controls.TouchButton, true)) { MouseEvent(MOUSEEVENTF_LEFTUP); } }
public void touchesBegan(object sender, TouchpadEventArgs arg) { pastTime = DateTime.Now; firstTouch = arg.touches[0]; }
public void touchButtonDown(object sender, TouchpadEventArgs arg) { if (arg.touches == null) { //No touches, finger on upper portion of touchpad if(!mapTouchPad(DS4Controls.TouchUpper)) performMiddleClick(); } else if (!Global.getLowerRCOff(deviceNum) && arg.touches[0].hwX > (1920 * 3)/4 && arg.touches[0].hwY > (960 * 3)/4) { performRightClick(); } else if (arg.touches.Length>1 && !mapTouchPad(DS4Controls.TouchMulti)) { performRightClick(); } else if (arg.touches.Length==1 && !mapTouchPad(DS4Controls.TouchButton)) { rightClick = false; MouseEvent(MOUSEEVENTF_LEFTDOWN); } }
public void handleTouchpad(byte[] data, bool touchPadIsDown) { bool _isActive = (data[0 + TOUCHPAD_DATA_OFFSET] >> 7) != 0 ? false : true; // >= 1 touch detected bool _isActive2 = (data[4 + TOUCHPAD_DATA_OFFSET] >> 7) != 0 ? false : true; // > 1 touch detected byte touchID = (byte)(data[0 + TOUCHPAD_DATA_OFFSET] & 0x7F); byte touchID2 = (byte)(data[4 + TOUCHPAD_DATA_OFFSET] & 0x7F); int currentX = data[1 + TOUCHPAD_DATA_OFFSET] + ((data[2 + TOUCHPAD_DATA_OFFSET] & 0xF) * 255); int currentY = ((data[2 + TOUCHPAD_DATA_OFFSET] & 0xF0) >> 4) + (data[3 + TOUCHPAD_DATA_OFFSET] * 16); //add secondary touch data int currentX2 = data[5 + TOUCHPAD_DATA_OFFSET] + ((data[6 + TOUCHPAD_DATA_OFFSET] & 0xF) * 255); int currentY2 = ((data[6 + TOUCHPAD_DATA_OFFSET] & 0xF0) >> 4) + (data[7 + TOUCHPAD_DATA_OFFSET] * 16); if (_isActive) { if (!lastTouchPadIsDown && touchPadIsDown && TouchButtonDown != null) { TouchpadEventArgs args = null; Touch t0 = new Touch(currentX, currentY, touchID); if (_isActive2) { Touch t1 = new Touch(currentX2, currentY2, touchID2); args = new TouchpadEventArgs(touchPadIsDown, t0, t1); } else { args = new TouchpadEventArgs(touchPadIsDown, t0); } TouchButtonDown(this, args); } else if (lastTouchPadIsDown && !touchPadIsDown && TouchButtonUp != null) { TouchpadEventArgs args = null; Touch t0 = new Touch(currentX, currentY, touchID); if (_isActive2) { Touch t1 = new Touch(currentX2, currentY2, touchID2); args = new TouchpadEventArgs(touchPadIsDown, t0, t1); } else { args = new TouchpadEventArgs(touchPadIsDown, t0); } TouchButtonUp(this, args); } if (!lastIsActive || (_isActive2 && !lastIsActive2)) { if (TouchesBegan != null) { TouchpadEventArgs args = null; Touch t0 = new Touch(currentX, currentY, touchID); if (_isActive2 && !lastIsActive2) { Touch t1 = new Touch(currentX2, currentY2, touchID2); args = new TouchpadEventArgs(touchPadIsDown, t0, t1); } else { args = new TouchpadEventArgs(touchPadIsDown, t0); } TouchesBegan(this, args); } } else if (lastIsActive) { if (TouchesMoved != null) { TouchpadEventArgs args = null; Touch t0Prev = new Touch(lastTouchPadX, lastTouchPadY, lastTouchID); Touch t0 = new Touch(currentX, currentY, touchID, t0Prev); if (_isActive && _isActive2) { Touch t1Prev = new Touch(lastTouchPadX2, lastTouchPadY2, lastTouchID2); Touch t1 = new Touch(currentX2, currentY2, touchID2, t1Prev); args = new TouchpadEventArgs(touchPadIsDown, t0, t1); } else { args = new TouchpadEventArgs(touchPadIsDown, t0); } TouchesMoved(this, args); } } else { } lastTouchPadX = currentX; lastTouchPadY = currentY; //secondary touch data lastTouchPadX2 = currentX2; lastTouchPadY2 = currentY2; lastTouchPadIsDown = touchPadIsDown; } else { if (lastIsActive) { if (TouchesEnded != null) { TouchpadEventArgs args = null; Touch t0 = new Touch(currentX, currentY, touchID); if (lastIsActive2) { Touch t1 = new Touch(currentX2, currentY2, touchID2); args = new TouchpadEventArgs(touchPadIsDown, t0, t1); } else { args = new TouchpadEventArgs(touchPadIsDown, t0); } TouchesEnded(this, args); } } if (touchPadIsDown && !lastTouchPadIsDown) { TouchButtonDown(this, new TouchpadEventArgs(touchPadIsDown, null, null)); } else if (!touchPadIsDown && lastTouchPadIsDown) { TouchButtonUp(this, new TouchpadEventArgs(touchPadIsDown, null, null)); } } lastIsActive = _isActive; lastIsActive2 = _isActive2; lastTouchID = touchID; lastTouchID2 = touchID2; lastTouchPadIsDown = touchPadIsDown; }
public void touchButtonUp(object sender, TouchpadEventArgs arg) { if (arg.touches == null) { //No touches, finger on upper portion of touchpad mapTouchPad(DS4Controls.TouchUpper,true); } else if (arg.touches.Length > 1) mapTouchPad(DS4Controls.TouchMulti, true); else if (!rightClick && arg.touches.Length == 1 && !mapTouchPad(DS4Controls.TouchButton, true)) { MouseEvent(MOUSEEVENTF_LEFTUP); } }
public void touchesEnded(object sender, TouchpadEventArgs arg) { if (Global.getTapSensitivity(deviceNum) != 0) { DateTime test = DateTime.Now; if (test <= (pastTime + TimeSpan.FromMilliseconds((double)Global.getTapSensitivity(deviceNum) * 2)) && !arg.touchButtonPressed) { if (Math.Abs(firstTouch.hwX - arg.touches[0].hwX) < 10 && Math.Abs(firstTouch.hwY - arg.touches[0].hwY) < 10) performLeftClick(); } } }
public void touchesMoved(object sender, TouchpadEventArgs arg) { if (arg.touches.Length == 1) { double sensitivity = Global.getTouchSensitivity(deviceNum) / 100.0; int mouseDeltaX = (int)(sensitivity * (arg.touches[0].deltaX)); int mouseDeltaY = (int)(sensitivity * (arg.touches[0].deltaY)); MoveCursorBy(mouseDeltaX, mouseDeltaY); } else if (arg.touches.Length == 2) { 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 int lastMidX = (lastT0.hwX + lastT1.hwX) / 2, lastMidY = (lastT0.hwY + lastT1.hwY) / 2, currentMidX = (T0.hwX + T1.hwX) / 2, currentMidY = (T0.hwY + T1.hwY) / 2; // XXX Will controller swap touch IDs? double coefficient = Global.getScrollSensitivity(deviceNum); // 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; MouseWheel((int)(coefficient * (lastMidY - currentMidY)), (int)(coefficient * (currentMidX - lastMidX))); } }
public void handleTouchpad(byte[] data, bool touchPadIsDown) { bool _isActive = (data[0 + TOUCHPAD_DATA_OFFSET] >> 7) != 0 ? false : true; // >= 1 touch detected bool _isActive2 = (data[4 + TOUCHPAD_DATA_OFFSET] >> 7) != 0 ? false : true; // > 1 touch detected byte touchID = (byte)(data[0 + TOUCHPAD_DATA_OFFSET] & 0x7F); byte touchID2 = (byte)(data[4 + TOUCHPAD_DATA_OFFSET] & 0x7F); int currentX = data[1 + TOUCHPAD_DATA_OFFSET] + ((data[2 + TOUCHPAD_DATA_OFFSET] & 0xF) * 255); int currentY = ((data[2 + TOUCHPAD_DATA_OFFSET] & 0xF0) >> 4) + (data[3 + TOUCHPAD_DATA_OFFSET] * 16); //add secondary touch data int currentX2 = data[5 + TOUCHPAD_DATA_OFFSET] + ((data[6 + TOUCHPAD_DATA_OFFSET] & 0xF) * 255); int currentY2 = ((data[6 + TOUCHPAD_DATA_OFFSET] & 0xF0) >> 4) + (data[7 + TOUCHPAD_DATA_OFFSET] * 16); if (_isActive) { if (!lastTouchPadIsDown && touchPadIsDown && TouchButtonDown != null) { TouchpadEventArgs args = null; Touch t0 = new Touch(currentX, currentY, touchID); if (_isActive2) { Touch t1 = new Touch(currentX2, currentY2, touchID2); args = new TouchpadEventArgs(touchPadIsDown, t0, t1); } else args = new TouchpadEventArgs(touchPadIsDown, t0); TouchButtonDown(this, args); } else if (lastTouchPadIsDown && !touchPadIsDown && TouchButtonUp != null) { TouchpadEventArgs args = null; Touch t0 = new Touch(currentX, currentY, touchID); if (_isActive2) { Touch t1 = new Touch(currentX2, currentY2, touchID2); args = new TouchpadEventArgs(touchPadIsDown, t0, t1); } else args = new TouchpadEventArgs(touchPadIsDown, t0); TouchButtonUp(this, args); } if (!lastIsActive || (_isActive2 && !lastIsActive2)) { if (TouchesBegan != null) { TouchpadEventArgs args = null; Touch t0 = new Touch(currentX, currentY, touchID); if (_isActive2 && !lastIsActive2) { Touch t1 = new Touch(currentX2, currentY2, touchID2); args = new TouchpadEventArgs(touchPadIsDown, t0, t1); } else args = new TouchpadEventArgs(touchPadIsDown, t0); TouchesBegan(this, args); } } else if (lastIsActive) { if (TouchesMoved != null) { TouchpadEventArgs args = null; Touch t0Prev = new Touch(lastTouchPadX, lastTouchPadY, lastTouchID); Touch t0 = new Touch(currentX, currentY, touchID, t0Prev); if (_isActive && _isActive2) { Touch t1Prev = new Touch(lastTouchPadX2, lastTouchPadY2, lastTouchID2); Touch t1 = new Touch(currentX2, currentY2, touchID2, t1Prev); args = new TouchpadEventArgs(touchPadIsDown, t0, t1); } else args = new TouchpadEventArgs(touchPadIsDown, t0); TouchesMoved(this, args); } } else { } lastTouchPadX = currentX; lastTouchPadY = currentY; //secondary touch data lastTouchPadX2 = currentX2; lastTouchPadY2 = currentY2; lastTouchPadIsDown = touchPadIsDown; } else { if (lastIsActive) { if (TouchesEnded != null) { TouchpadEventArgs args = null; Touch t0 = new Touch(currentX, currentY, touchID); if (lastIsActive2) { Touch t1 = new Touch(currentX2, currentY2, touchID2); args = new TouchpadEventArgs(touchPadIsDown, t0, t1); } else args = new TouchpadEventArgs(touchPadIsDown, t0); TouchesEnded(this, args); } } if (touchPadIsDown && !lastTouchPadIsDown) { TouchButtonDown(this, new TouchpadEventArgs(touchPadIsDown, null, null)); } else if (!touchPadIsDown && lastTouchPadIsDown) { TouchButtonUp(this, new TouchpadEventArgs(touchPadIsDown, null, null)); } } lastIsActive = _isActive; lastIsActive2 = _isActive2; lastTouchID = touchID; lastTouchID2 = touchID2; lastTouchPadIsDown = touchPadIsDown; }