diff --git a/GestureSign.Daemon/Input/PointCapture.cs b/GestureSign.Daemon/Input/PointCapture.cs index 948e70f..42d171e 100644 --- a/GestureSign.Daemon/Input/PointCapture.cs +++ b/GestureSign.Daemon/Input/PointCapture.cs @@ -1,13 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Drawing; -using System.Linq; -using System.Runtime.InteropServices; -using System.Threading.Tasks; -using System.Windows.Forms; -using WindowsInput; -using GestureSign.Common; +using GestureSign.Common; using GestureSign.Common.Applications; using GestureSign.Common.Configuration; using GestureSign.Common.Gestures; @@ -17,6 +8,15 @@ using GestureSign.PointPatterns; using ManagedWinapi.Hooks; using ManagedWinapi.Windows; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Drawing; +using System.Linq; +using System.Runtime.InteropServices; +using System.Threading; +using System.Threading.Tasks; +using WindowsInput; using Timer = System.Windows.Forms.Timer; namespace GestureSign.Daemon.Input @@ -35,6 +35,7 @@ public class PointCapture : ILoadable, IPointCapture, IDisposable private readonly PointerInputTargetWindow _pointerInputTargetWindow; private readonly List _pointPatternCache = new List(); private readonly Timer _timeoutTimer = new Timer(); + private readonly System.Threading.Timer _blockTouchDelayTimer; private Dictionary> _pointsCaptured; // Create variable to hold the only allowed instance of this class @@ -51,6 +52,8 @@ public class PointCapture : ILoadable, IPointCapture, IDisposable private bool disposedValue = false; // To detect redundant calls + private int? _blockTouchInputThreshold; + #endregion #region PInvoke @@ -195,6 +198,7 @@ protected PointCapture() if (AppConfig.UiAccess) { + _blockTouchDelayTimer = new System.Threading.Timer(UpdateBlockTouchInputThresholdCallback, null, Timeout.Infinite, Timeout.Infinite); ForegroundApplicationsChanged += PointCapture_ForegroundApplicationsChanged; } @@ -220,6 +224,7 @@ protected virtual void Dispose(bool disposing) _pointerInputTargetWindow?.Dispose(); _inputProvider?.Dispose(); _timeoutTimer?.Dispose(); + _blockTouchDelayTimer?.Dispose(); } if (_hWinEventHook != IntPtr.Zero) @@ -266,9 +271,7 @@ private void PointCapture_ForegroundApplicationsChanged(object sender, IApplicat { var userAppList = apps.Where(application => application is UserApp).ToList(); if (userAppList.Count == 0) return; - int maxBlockTouchInputThreshold = userAppList.Cast().Max(app => app.BlockTouchInputThreshold); - - _pointerInputTargetWindow.BlockTouchInputThreshold = maxBlockTouchInputThreshold; + UpdateBlockTouchInputThreshold(userAppList.Cast().Max(app => app.BlockTouchInputThreshold)); } } @@ -301,6 +304,7 @@ protected void PointEventTranslator_PointMove(object sender, InputPointsEventArg AddPoint(e.InputPointList); } + UpdateBlockTouchInputThreshold(); } protected void PointEventTranslator_PointUp(object sender, InputPointsEventArgs e) @@ -355,12 +359,32 @@ protected void PointEventTranslator_PointUp(object sender, InputPointsEventArgs } SourceDevice = Device.None; + + UpdateBlockTouchInputThreshold(); } #endregion #region Private Methods + private void UpdateBlockTouchInputThreshold(int? threshold = null) + { + if (!AppConfig.UiAccess) return; + + if (threshold != null) + _blockTouchInputThreshold = threshold; + if (_blockTouchInputThreshold != null) + _blockTouchDelayTimer.Change(100, Timeout.Infinite); + } + + private void UpdateBlockTouchInputThresholdCallback(object o) + { + if (!_blockTouchInputThreshold.HasValue) return; + + _pointerInputTargetWindow.BlockTouchInputThreshold = _blockTouchInputThreshold.Value; + _blockTouchInputThreshold = null; + } + private void GestureRecognizedCallback(object sender, EventArgs e) { _timeoutTimer.Stop(); @@ -374,7 +398,7 @@ private bool TryBeginCapture(List firstPoint) PointsCapturedEventArgs captureStartedArgs = new PointsCapturedEventArgs(firstPoint.Select(p => p.Point).ToList()); OnCaptureStarted(captureStartedArgs); - _pointerInputTargetWindow.BlockTouchInputThreshold = Mode == CaptureMode.Normal ? captureStartedArgs.BlockTouchInputThreshold : 0; + UpdateBlockTouchInputThreshold(Mode == CaptureMode.Normal ? captureStartedArgs.BlockTouchInputThreshold : 0); if (captureStartedArgs.Cancel) return false;