private void OnSynapticsPacket() { synTouchPad.LoadPacket(synPacket); var numberOfFingers = synPacket.GetLongProperty(SynPacketProperty.SP_ExtraFingerState); numberOfFingers &= 0b11; if (numberOfFingers == 2) { cumulativeYDelta += synPacket.YDelta; if (Math.Abs(cumulativeYDelta) > 100) { Dispatcher.Invoke(new Action(() => { Decorator listViewBorder = VisualTreeHelper.GetChild(SearchResultsListView, 0) as Decorator; ScrollViewer listViewScrollViewer = listViewBorder.Child as ScrollViewer; double vOffset = cumulativeYDelta < 0 ? -3 : 3; listViewScrollViewer.ScrollToVerticalOffset(listViewScrollViewer.VerticalOffset + vOffset); }), DispatcherPriority.ContextIdle); cumulativeYDelta = 0; } } else { cumulativeYDelta = 0; } }
private bool LoadPacket() { // if (_disposed) return false; try { return(_device.LoadPacket(_packet) == 0); } catch (COMException ex) when(ex.ErrorCode == (int)SynError.Sequence) { // From Synaptics SDK documentation: // // Packet data was correctly exported but the packet's sequence // number was not sequential with the previously exported packet. Debug.WriteLine("Packet sequence out of order"); return(true); } catch (COMException ex) when(ex.ErrorCode == (int)SynError.Fail) { // From Synaptics SDK documentation: // // The device packet queue is empty. Debug.WriteLine("Packet queue is empty"); return(false); } }
static private void SynTP_Dev_OnPacket() { var result = device.LoadPacket(packet); SynFingerFlags fingerState; if (Enum.TryParse(packet.FingerState.ToString(), out fingerState)) { if (fingerState.HasFlag(SynFingerFlags.SF_FingerTap3)) { Console.WriteLine($"Tapped {counter++}"); } } }
static private void SynTP_Dev_OnPacket() { var result = device.LoadPacket(packet); SynFingerFlags fingerState; SynMultiFingerGestureFlags multiFingerGestureState = SynMultiFingerGestureFlags.SF_UnacquireAllGestures; // if (Enum.TryParse(packet.FingerState.ToString(), out fingerState)) // { // if (fingerState.HasFlag(SynFingerFlags.SF_FingerTap3)) // { // Console.WriteLine($"You tapped with 3 fingers and moved"); // } // } Console.WriteLine("FingerState: " + packet.FingerState + ", ExtendedState: " + packet.ExtendedState); //doFingerState(multiFingerGestureState); doExtendedState(multiFingerGestureState); //doExtendedState2(multiFingerGestureState); }
//Event handler public void SynTP_Dev_OnPacket() { //SynTP_Dev.LoadPacket(SynTP_Pack); int loadPck = SynTP_Dev.LoadPacket(SynTP_Pack); if (loadPck == 1) { //ERR (12/3): Outputing 0s for FingerState, X, Y //ERR (2/11): Not detecting X,Y from touch Console.WriteLine(DateTime.Now + "Finger State: {0}", SynTP_Pack.FingerState); currFingerX = SynTP_Pack.X; Console.WriteLine(DateTime.Now + "Finger X:{0} Y:{1}", SynTP_Pack.X, SynTP_Pack.Y); currFingerY = SynTP_Pack.Y; //Interpret absolute (x, y) into 1 of 5 regions on touchpad //currRegion = getRegion(currFingerX, currFingerY); //currUnicode = getUnicode(currRegion); } }
static public void SynTP_Dev_OnPacket() { var result = device.LoadPacket(packet); if (packet.X > 1) { Console.SetCursorPosition(0, 1); Console.Write(new string(' ', Console.WindowWidth)); Console.SetCursorPosition(0, 1); Console.WriteLine("X:" + packet.X + " Y:" + packet.Y); x = Screen.PrimaryScreen.Bounds.Width; y = Screen.PrimaryScreen.Bounds.Height; targetx = (int)((packet.X - Xmin) / (Xmax - Xmin) * x); targety = (int)(((Ymax - Ymin) - (packet.Y - Ymin)) / (Ymax - Ymin) * y); SetCursorPos((int)targetx, (int)targety); Console.SetCursorPosition(0, 5); Console.Write(new string(' ', Console.WindowWidth)); Console.SetCursorPosition(0, 5); Console.WriteLine("X:" + targetx + " Y:" + targety); } }
/* Event handler for Synaptics API touch events */ void SynDevCtrl_OnPacket() { SynPacketCtrl SynPacCtrl = new SynPacketCtrl(); SynDevCtrl.LoadPacket(SynPacCtrl); if (SynPacCtrl.GetLongProperty(SynPacketProperty.SP_ExtraFingerState) == 2) { isMultitouch = true; } else if (SynPacCtrl.GetLongProperty(SynPacketProperty.SP_ExtraFingerState) == 1) { isMultitouch = false; } else if (SynPacCtrl.GetLongProperty(SynPacketProperty.SP_ExtraFingerState) == 0) { isMultitouch = false; } // 8 is a "magic number" made through testing. It specifies the boundary for a "normal" finger width. // This should probably be configurable in the future. if ((SynPacCtrl.W > 8) || isMultitouch) { // Width is higher than normal. We probably have two fingers on the touchpad. // OR We actually found a native multitouch! // Disable touchpad input to the OS. // We will be exclusively handling the touchpad during these events. // Native multitouch caveat! Native two-finger scrolling WILL compete with this. // Disable it if you prever MultiTouchEnabler's scrolling. // Todo.. This is for coexisting nicely with native multitouch non-scrolling gestures. /*if (SynPacCtrl.GetLongProperty(SynPacketProperty.SP_ExtraFingerState) == 2) * { * //Check space between fingers. We don't want to interfere with other gestures... * if (SynPacCtrl.XMickeys > 5) * { * if (isExclusivityAcquired) * SynDevCtrl.Unacquire(); * isExclusivityAcquired = false; * gestureMode = 1; * } * * }*/ if (!isExclusivityAcquired && gestureMode == 0) { try { // This gives us exclusive control of the touchpad. // Other software, like the OS, will not recieve the touch events. SynDevCtrl.Acquire(0); isExclusivityAcquired = true; } catch { // This might happen sometimes. It's okay. isExclusivityAcquired = false; } } if (gestureMode == 0) { // Scroll the mouse! // Use the user-defined scroll speed factor and the inversion setting to determine the scroll amount mouse_event(2048, 0, 0, SynPacCtrl.YMickeys * scrollSpeed * scrollInversion, GetMessageExtraInfo()); } else { gestureMode = 1; } } else { // We need to relinquish exclusivity of the touchpad. if (isExclusivityAcquired) { SynDevCtrl.Unacquire(); } isExclusivityAcquired = false; } // We build up a lot of memory usage if we let this go on normally // Force the Garbage Collector to do its job! SynPacCtrl = null; GC.Collect(); GC.WaitForPendingFinalizers(); }
private void OnPacket() { var packet = new SynPacketCtrl(); _synTouchPad.LoadPacket(packet); CheckTappingProperty(); var nof = packet.GetLongProperty(SynPacketProperty.SP_ExtraFingerState) & 3; var fstate = packet.GetLongProperty(SynPacketProperty.SP_FingerState); var xd = packet.GetLongProperty(SynPacketProperty.SP_XDelta); var yd = packet.GetLongProperty(SynPacketProperty.SP_YDelta); var y = packet.GetLongProperty(SynPacketProperty.SP_Y); var x = packet.GetLongProperty(SynPacketProperty.SP_X); _log.LogDebug("got packet"); _log.LogDebug("nof=" + nof); _log.LogDebug("fstate=" + fstate); _log.LogDebug("xd=" + xd); _log.LogDebug("yd=" + yd); _log.LogDebug("x=" + x); _log.LogDebug("y=" + y); if (nof > _tapMaxNof) { _tapMaxNof = nof; } //handle tapping if (nof > _tapLastNof) // on press { _tapDone = false; if (nof >= 2) //on press of more than one finger { _tapStartTime = packet.GetLongProperty(SynPacketProperty.SP_TimeStamp); LockDeviceTap(true); } if (_tapLastNof == 0) //first touch { _tapTouchTime = packet.GetLongProperty(SynPacketProperty.SP_TimeStamp); NativeMethods.GetCursorPos(ref _tapTouchPos); _tapFirstTouchPos = new Point(x, y); } } else if (nof < _tapLastNof) // on release { if (nof == 0) { _tapDone = false; _tapMaxNof = 0; } if (_tapLastNof >= 1 && !_tapDone) { var ok = false; var tstamp = packet.GetLongProperty(SynPacketProperty.SP_TimeStamp); if (tstamp - _tapTouchTime < _config.SwipeBorderSpeedMs && (_tapFirstTouchPos.X > (_xmax - _config.SwipeBorderStartInsetX) || _tapFirstTouchPos.X < (_xmin + _config.SwipeBorderStartInsetX) || _tapFirstTouchPos.Y > (_ymax - _config.SwipeBorderStartInsetY) || _tapFirstTouchPos.Y < (_xmin + _config.SwipeBorderStartInsetY))) { _log.LogDebug("first touch: " + _tapFirstTouchPos.X + "/" + _tapFirstTouchPos.Y); _log.LogDebug("current touch: " + x + "/" + y); if (_tapFirstTouchPos.X > (_xmax - _config.SwipeBorderStartInsetX) && x < _tapFirstTouchPos.X - _config.SwipeBorderInsetX) { _log.LogDebug("swipe border right"); ok = OnActionEvent(ActionType.SwipeBorderRight); NativeMethods.SetCursorPos(_tapTouchPos.X, _tapTouchPos.Y); } else if (_tapFirstTouchPos.X < (_xmin + _config.SwipeBorderStartInsetX) && x > _tapFirstTouchPos.X + _config.SwipeBorderInsetX) { _log.LogDebug("swipe border left"); ok = OnActionEvent(ActionType.SwipeBorderLeft); NativeMethods.SetCursorPos(_tapTouchPos.X, _tapTouchPos.Y); } else if (_tapFirstTouchPos.Y > (_ymax - _config.SwipeBorderStartInsetY) && y < _tapFirstTouchPos.Y - _config.SwipeBorderInsetY) { _log.LogDebug("swipe border top"); ok = OnActionEvent(ActionType.SwipeBorderTop); NativeMethods.SetCursorPos(_tapTouchPos.X, _tapTouchPos.Y); } else if (_tapFirstTouchPos.Y < (_ymin + _config.SwipeBorderStartInsetY) && y > _tapFirstTouchPos.Y + _config.SwipeBorderInsetY) { _log.LogDebug("swipe border bottom"); ok = OnActionEvent(ActionType.SwipeBorderBottom); NativeMethods.SetCursorPos(_tapTouchPos.X, _tapTouchPos.Y); } } else if (tstamp - _tapTouchTime < _config.TapMaxMsBetween && Math.Abs(_tapFirstTouchPos.X - x) < _config.TapMaxDistance && Math.Abs(_tapFirstTouchPos.Y - y) < _config.TapMaxDistance) //time between now and first touch < _config { if (_tapLastNof == 1 && _tapMaxNof <= 1) { ok = OnActionEvent(ActionType.MouseTapOne); } else if (_tapLastNof == 2 && _tapMaxNof <= 2) { ok = OnActionEvent(ActionType.MouseTapTwo); } else if (_tapLastNof == 3 && _tapMaxNof <= 3) { ok = OnActionEvent(ActionType.MouseTapThree); } } else if (tstamp - _tapTouchTime > _config.MouseTapsLongMs && !_tapDone) { if (Math.Abs(_tapFirstTouchPos.X - x) < _config.MouseTapsLongMovingArea && Math.Abs(_tapFirstTouchPos.Y - y) < _config.MouseTapsLongMovingArea) { if (_tapLastNof == 1 && _tapMaxNof <= 1) { ok = OnActionEvent(ActionType.MouseTapOneLong); } else if (_tapLastNof == 2 && _tapMaxNof <= 2) { ok = OnActionEvent(ActionType.MouseTapTwoLong); } else if (_tapLastNof == 3 && _tapMaxNof <= 3) { ok = OnActionEvent(ActionType.MouseTapThreeLong); } } } #region old code /* * if (tstamp - tapTouchTime < _config.TapMaxMsBetween) //time between now and first touch < _config * { * if (tapLastNof == 1) * { * ok = OnActionEvent(ActionType.MouseTapOne); * } * else if (tapLastNof == 2) * { * ok = OnActionEvent(ActionType.MouseTapTwo); * } * else if (tapLastNof == 3) { * ok = OnActionEvent(ActionType.MouseTapThree); * } * } * else if ( * tstamp - tapTouchTime >= _config.TapMaxMsBetween && //time between now and first touch > _config * tstamp - tapStartTime < _config.TapMaxMsBetween) //time between now and last touch < _config * { * if (tapLastNof == 2) * { * ok = OnActionEvent(ActionType.MouseTapOneOne); * } * else if (tapLastNof == 3) * { * ok = OnActionEvent(ActionType.MouseTapTwoOne); * } * //if only one touch has been recognized and time is longer than xyz ms, check if long press * } * else if (tapLastNof == 1 && tstamp - tapTouchTime > _config.MouseTapOneLongMs) * { * //compare end point to start point * Point releasePoint = tapTouchPos; * NativeMethods.GetCursorPos(ref releasePoint); * //only catch difference of 100 (px?) * if (Math.Abs(releasePoint.X - tapTouchPos.X) < _config.MouseTapOneLongMovingArea && Math.Abs(releasePoint.Y - tapTouchPos.Y) < _config.MouseTapOneLongMovingArea) * { * ok = OnActionEvent(ActionType.MouseTapOneLong); * } * } */ #endregion //if there is an action, move cursor back to start position where the action has been performed if (ok) { _tapDone = true; //NativeMethods.SetCursorPos(tapTouchPos.X, tapTouchPos.Y); //tapStartTime -= _config.TapMaxMsBetween; } _tapStartTime -= _config.TapMaxMsBetween; _tapLastNof = nof; return; } } /* * if (isDeviceTapLocked) * { * if (Math.Abs(xd) < 800) tapDistance += Math.Abs(xd); * if (Math.Abs(yd) < 800) tapDistance += Math.Abs(yd); * if ((fstate & (int)SYNCTRLLib.SynFingerFlags.SF_FingerPresent) == 0) * LockDeviceTap(false); * } */ _tapLastNof = nof; //handle scrolling if ((fstate & (int)SynFingerFlags.SF_FingerPresent) != 0) { if (_scrollTouchTime == 0) { NativeMethods.GetCursorPos(ref _scrollTouchPos); _scrollTouchTime = packet.GetLongProperty(SynPacketProperty.SP_TimeStamp); } if (nof == 2) { if (_isPadAcquired && _scrollLinearEdgeY && (_scrollDir == ScrollDirection.Up || _scrollDir == ScrollDirection.Down)) { if (_ylo <= y && y <= _yhi) { _scrollNotEdgeY = true; } else if (_scrollNotEdgeY && ((y < _ylo && _scrollLastYDelta < 0) || (y > _yhi && _scrollLastYDelta > 0))) { DoScroll(_scrollLastXDelta, _scrollLastYDelta); return; } } if (_isPadAcquired && _scrollLinearEdgeX && (_scrollDir == ScrollDirection.Left || _scrollDir == ScrollDirection.Right)) { if (_xlo <= x && x <= _xhi) { _scrollNotEdgeX = true; } else if (_scrollNotEdgeX && ((x < _xlo && _scrollLastXDelta < 0) || (x > _xhi && _scrollLastXDelta > 0))) { DoScroll(_scrollLastXDelta, _scrollLastYDelta); return; } /* * if (ylo <= y && x <= yhi) scrollNotEdgeY = true; * else if (scrollNotEdgeY && ((y < ylo && scrollLastYDelta < 0) || * (y > yhi && scrollLastYDelta > 0))) * { * DoScroll(scrollLastXDelta, scrollLastYDelta); * return; * } */ } if ((fstate & (int)SynFingerFlags.SF_FingerMotion) != 0) { if (!_isPadAcquired) { _swipeDone = false; //start left/right swipe AcquirePad(true); var tstamp = packet.GetLongProperty(SynPacketProperty.SP_TimeStamp); if (tstamp - _scrollTouchTime < 1000) { NativeMethods.SetCursorPos(_scrollTouchPos.X, _scrollTouchPos.Y); } } if (_isPadAcquired) { _swipeXDelta += xd; _swipeYDelta += yd; if (_swipeXDelta < -1 * _config.SwipeTwoMovementXDirection && Math.Abs(_swipeYDelta) < _config.SwipeTwoMovementXOrthogonal) { //left _scrollDir = ScrollDirection.Left; if (!_swipeDone) { OnActionEvent(ActionType.SwipeTwoLeft); } _swipeDone = true; } else if (_swipeXDelta > _config.SwipeTwoMovementXDirection && Math.Abs(_swipeYDelta) < _config.SwipeTwoMovementXOrthogonal) { //right _scrollDir = ScrollDirection.Right; if (!_swipeDone) { OnActionEvent(ActionType.SwipeTwoRight); } _swipeDone = true; } else if (Math.Abs(_swipeXDelta) < _config.SwipeTwoMovementYDirection && _swipeYDelta < -1 * _config.SwipeTwoMovementYOrthogonal) { //down _swipeDone = true; _scrollDir = ScrollDirection.Down; } else if (Math.Abs(_swipeXDelta) < _config.SwipeTwoMovementYDirection && _swipeYDelta > _config.SwipeTwoMovementYOrthogonal) { //up _swipeDone = true; _scrollDir = ScrollDirection.Up; } _scrollLastXDelta = xd; _scrollLastYDelta = yd; if (_scrollDir != ScrollDirection.None) { DoScroll(xd, yd); } } } } else if (nof == 3) { if ((fstate & (int)SynFingerFlags.SF_FingerMotion) != 0) { if (!_isPadAcquired) { AcquirePad(true); _swipeDone = false; } if (_isPadAcquired && !_swipeDone) { _swipeXDelta += xd; _swipeYDelta += yd; if (_swipeXDelta < -1 * _config.SwipeThreeMovementXDirection && Math.Abs(_swipeYDelta) < _config.SwipeThreeMovementXOrthogonal) { //left _swipeDone = true; OnActionEvent(ActionType.SwipeThreeLeft); } else if (_swipeXDelta > _config.SwipeThreeMovementXDirection && Math.Abs(_swipeYDelta) < _config.SwipeThreeMovementXOrthogonal) { //right _swipeDone = true; OnActionEvent(ActionType.SwipeThreeRight); } else if (Math.Abs(_swipeXDelta) < _config.SwipeThreeMovementYOrthogonal && _swipeYDelta < -1 * _config.SwipeThreeMovementYDirection) { //down _swipeDone = true; OnActionEvent(ActionType.SwipeThreeDown); } else if (Math.Abs(_swipeXDelta) < _config.SwipeThreeMovementYOrthogonal && _swipeYDelta > _config.SwipeThreeMovementYDirection) { //up _swipeDone = true; OnActionEvent(ActionType.SwipeThreeUp); } } } } else { _scrollLastXDelta = _scrollLastYDelta = 0; _swipeXDelta = _swipeYDelta = 0; _swipeDone = false; _scrollDir = ScrollDirection.None; AcquirePad(false); _scrollBufferX = _scrollBufferY = 0; _scrollNotEdgeX = _scrollNotEdgeY = false; } } else { _scrollTouchTime = 0; _scrollLastXDelta = _scrollLastYDelta = 0; _swipeXDelta = _swipeYDelta = 0; _swipeDone = false; _scrollDir = ScrollDirection.None; AcquirePad(false); _scrollBufferX = _scrollBufferY = 0; _scrollNotEdgeX = _scrollNotEdgeY = false; } }
void synDev_OnPacket() { synDev.LoadPacket(synPacket); if (calibrateState == 0) { int X, Y; X = Clamp(Clamp(synPacket.X - XMin, XMax, 0) * wWidth / (XMax - XMin), wWidth, 0); Y = Clamp(Clamp(YMax - synPacket.Y, YMax, 0) * wHeight / (YMax - YMin), wHeight, 0); if (contacts[0].PointerInfo.PointerId == 0 && synPacket.FingerState != 0 && synPacket.X > 1 && synPacket.Y > 1) { contacts[0] = MakePointerTouchInfo(X, Y, synPacket.W, 1); //contacts[1] = MakePointerTouchInfo(650, 500, 2, 2); bool success = TouchInjector.InjectTouchInput(1, contacts); } else if (synPacket.FingerState != 0 && synPacket.X > 1 && synPacket.Y > 1) { contacts[0].PointerInfo.PtPixelLocation.X = X; contacts[0].PointerInfo.PtPixelLocation.Y = Y; contacts[0].ContactArea.left = X - synPacket.W; contacts[0].ContactArea.right = X + synPacket.W; contacts[0].ContactArea.top = Y - synPacket.W; contacts[0].ContactArea.bottom = Y + synPacket.W; contacts[0].PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT; //contacts[1].PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT; bool s = TouchInjector.InjectTouchInput(1, contacts); } else if ((contacts[0].PointerInfo.PointerFlags & PointerFlags.UP) != PointerFlags.UP) { //release them contacts[0].PointerInfo.PointerFlags = PointerFlags.UP; //contacts[1].PointerInfo.PointerFlags = PointerFlags.UP; bool success2 = TouchInjector.InjectTouchInput(1, contacts); contacts[0].PointerInfo.PointerId = 0; } touchLabel.Text = "X: " + X + ", Y: " + Y + ", W: " + synPacket.W + ", Z: " + synPacket.Z; } else { if (synPacket.FingerState != 0 && lastFingerState == 0) { switch (calibrateState) { case 1: XMin = synPacket.X; calibrateLabel.Text = "Swipe from top."; calibrateState = 2; break; case 2: YMax = synPacket.Y; calibrateLabel.Text = "Swipe from right."; calibrateState = 3; break; case 3: XMax = synPacket.X; calibrateLabel.Text = "Swipe from bottom."; calibrateState = 4; break; case 4: YMin = synPacket.Y; calibrateLabel.Text = "Done."; calibrateState = 5; Settings.Default.XMin = XMin; Settings.Default.XMax = XMax; Settings.Default.YMin = YMin; Settings.Default.YMax = YMax; Settings.Default.Save(); break; case 5: calibrateState = 0; break; } updateCalibrationStatusLabel(); } } lastFingerState = synPacket.FingerState; }