private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (DeviceHandle != -1) { synDev.SetLongProperty(SynDeviceProperty.SP_DisableState, oldDisableState); synDev.Unacquire(); } }
public void StopTouchCapture() { EnsureNotDisposed(); if (!_acquired) { return; } _device.OnPacket -= OnDevicePacket; _device.Unacquire(); _acquired = false; if (_touching) { TouchEnded?.Invoke(this, EventArgs.Empty); _touching = false; } }
/* 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(); }