private async void EndCapture()
        {

            // Create points capture event args, to be used to send off to event subscribers or to simulate original Touch event
            PointsCapturedEventArgs pointsInformation = new PointsCapturedEventArgs(new List<List<Point>>(_pointsCaptured.Values));

            // Notify subscribers that capture has ended (draw end)
            OnCaptureEnded();
            State = CaptureState.Ready;

            if (_gestureTimeout)
            {
                _gestureTimeout = false;
                pointsInformation.GestureTimeout = true;
            }
            // Notify PointsCaptured event subscribers that points have been captured.
            //CaptureWindow GetGestureName
            OnBeforePointsCaptured(pointsInformation);

            if (pointsInformation.Cancel) return;

            if (pointsInformation.Delay)
            {
                _timeoutTimer.Interval = AppConfig.GestureTimeout;
                _timeoutTimer.Start();
            }
            else if (Mode == CaptureMode.Training && !(_pointsCaptured.Count == 1 && _pointsCaptured.Values.First().Count == 1))
            {
                try
                {
                    bool createdSetting;
                    using (new Mutex(false, "GestureSignControlPanel", out createdSetting)) { }
                    if (createdSetting)
                    {
                        string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "GestureSign.exe");
                        if (File.Exists(path))
                            using (Process daemon = new Process())
                            {
                                daemon.StartInfo.FileName = path;
                                daemon.StartInfo.Arguments = "/L";
                                // pipeClient.StartInfo.Arguments =            
                                //daemon.StartInfo.UseShellExecute = false;
                                daemon.Start();
                                daemon.WaitForInputIdle();
                            }
                    }
                }
                catch (Exception exception)
                {
                    Logging.LogException(exception);
                    MessageBox.Show(exception.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                if (OverlayGesture)
                {
                    OverlayGesture = false;
                }
                else
                {
                    _pointPatternCache.Clear();
                }
                _pointPatternCache.Add(new PointPattern(new List<List<Point>>(_pointsCaptured.Values)));

                var message = new Tuple<string, List<List<List<Point>>>>(GestureManager.Instance.GestureName, _pointPatternCache.Select(p => p.Points).ToList());
                if (await NamedPipe.SendMessageAsync(message, "GestureSignControlPanel"))
                    DisableTouchCapture();
            }

            // Fire recognized event if we found a gesture match, otherwise throw not recognized event
            if (GestureManager.Instance.GestureName != null)
                OnGestureRecognized(new RecognitionEventArgs(GestureManager.Instance.GestureName, pointsInformation.Points, pointsInformation.LastCapturedPoints));
            else
                OnGestureNotRecognized(new RecognitionEventArgs(pointsInformation.Points, pointsInformation.LastCapturedPoints));

            OnAfterPointsCaptured(pointsInformation);

        }
 protected virtual void OnCaptureCanceled(PointsCapturedEventArgs e)
 {
     if (CaptureCanceled != null) CaptureCanceled(this, e);
 }
        private bool TryBeginCapture(List<RawTouchData> firstTouch)
        {

            // Create capture args so we can notify subscribers that capture has started and allow them to cancel if they want.
            PointsCapturedEventArgs captureStartedArgs = new PointsCapturedEventArgs(firstTouch.Select(p => p.RawPoints).ToList());
            OnCaptureStarted(captureStartedArgs);

            _inputTargetWindow.InterceptTouchInput(captureStartedArgs.InterceptTouchInput && Mode == CaptureMode.Normal);

            if (captureStartedArgs.Cancel)
                return false;

            State = CaptureState.Capturing;

            // Clear old gesture from point list so we can start adding the new captures points to the list 
            _pointsCaptured = new Dictionary<int, List<Point>>(firstTouch.Count);
            if (AppConfig.IsOrderByLocation)
            {
                foreach (var rawTouchData in firstTouch.OrderBy(p => p.RawPoints.X))
                {
                    if (!_pointsCaptured.ContainsKey(rawTouchData.ContactIdentifier))
                        _pointsCaptured.Add(rawTouchData.ContactIdentifier, new List<Point>(30));
                }
            }
            else
            {
                foreach (var rawTouchData in firstTouch.OrderBy(p => p.ContactIdentifier))
                {
                    if (!_pointsCaptured.ContainsKey(rawTouchData.ContactIdentifier))
                        _pointsCaptured.Add(rawTouchData.ContactIdentifier, new List<Point>(30));
                }
            }
            AddPoint(firstTouch);
            return true;
        }
 protected virtual void OnBeforePointsCaptured(PointsCapturedEventArgs e)
 {
     if (BeforePointsCaptured != null) BeforePointsCaptured(this, e);
 }
 protected virtual void OnPointCaptured(PointsCapturedEventArgs e)
 {
     if (PointCaptured != null) PointCaptured(this, e);
 }
 protected virtual void OnAfterPointsCaptured(PointsCapturedEventArgs e)
 {
     if (AfterPointsCaptured != null) AfterPointsCaptured(this, e);
 }
        private void Instance_CaptureStarted(object sender, PointsCapturedEventArgs e)
        {
            var touchCapture = (ITouchCapture)sender;

            if (AppConfig.VisualFeedbackWidth <= 0 || touchCapture.Mode == CaptureMode.UserDisabled) return;

            if (_settingsChanged)
            {
                _settingsChanged = false;
                InitializeForm();
            }

            ClearSurfaces();
        }
 protected void MouseCapture_PointCaptured(object sender, PointsCapturedEventArgs e)
 {
     var touchCapture = (ITouchCapture)sender;
     if (touchCapture.Mode != CaptureMode.UserDisabled &&
         touchCapture.State == CaptureState.Capturing &&
         AppConfig.VisualFeedbackWidth > 0 &&
         !(e.Points.Count == 1 && e.Points.First().Count == 1))
     {
         if (_bitmap == null || _lastStroke == null)
         {
             ClearSurfaces();
             _bitmap = new DiBitmap(Screen.PrimaryScreen.Bounds.Size);
         }
         DrawSegments(e.Points);
     }
 }
 protected void MouseCapture_CaptureCanceled(object sender, PointsCapturedEventArgs e)
 {
     if (AppConfig.VisualFeedbackWidth > 0)
         EndDraw();
 }
        protected void TouchCapture_BeforePointsCaptured(object sender, PointsCapturedEventArgs e)
        {
            var touchCapture = (ITouchCapture)sender;

            if (touchCapture.Mode == CaptureMode.Training)
            {
                if (touchCapture.OverlayGesture)
                {
                    _gestureLevel++;
                }
                else
                {
                    _gestureLevel = 0;
                    _gestureMatchResult = null;
                }
            }

            if (e.GestureTimeout)
            {
                _gestureLevel = 0;
                _gestureMatchResult = null;
            }

            var sourceGesture = _gestureLevel == 0 ? _Gestures : _gestureMatchResult;
            GestureName = GetGestureSetNameMatch(e.Points, sourceGesture, out _gestureMatchResult);

            if (touchCapture.Mode != CaptureMode.Training)
            {
                if (_gestureMatchResult != null && _gestureMatchResult.Count != 0)
                {
                    _gestureLevel++;
                    e.Delay = true;
                }
                else
                {
                    _gestureLevel = 0;
                    _gestureMatchResult = null;
                }
            }
        }