public Form1() { InitializeComponent(); synAPI = new SynAPICtrlClass(); synDev = new SynDeviceCtrlClass(); synPacket = new SynPacketCtrlClass(); }
public API() { try { APICtrl = new SynAPICtrl(); Device = new SynDeviceCtrl(); Packet = new SynPacketCtrl(); IsAvailable = true; Init(); } catch (COMException) { IsAvailable = false; } }
public SearchResultsView() { InitializeComponent(); SearchResultsListView.ItemsSource = EverythingSearch.Instance.SearchResults; ((INotifyCollectionChanged)SearchResultsListView.Items).CollectionChanged += OnCollectionChanged; #if SYNAPTICS try { api = new SynAPICtrl(); synTouchPad = new SynDeviceCtrl(); synPacket = new SynPacketCtrl(); api.Initialize(); api.Activate(); deviceHandle = api.FindDevice(SynConnectionType.SE_ConnectionAny, SynDeviceType.SE_DeviceTouchPad, -1); synTouchPad.Select(deviceHandle); synTouchPad.Activate(); synTouchPad.OnPacket += OnSynapticsPacket; } catch (COMException) { } #endif }
/* 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; } }