protected void TouchCapture_CaptureStarted(object sender, PointsCapturedEventArgs e) { var touchCapture = (ITouchCapture)sender; if (touchCapture.Mode == CaptureMode.Training) { return; } if (Environment.OSVersion.Version.Major == 6) { IntPtr hwndCharmBar = FindWindow("NativeHWNDHost", "Charm Bar"); var window = SystemWindow.FromPointEx(SystemWindow.DesktopWindow.Rectangle.Right - 1, 1, true, true); if (window != null && window.HWnd.Equals(hwndCharmBar)) { e.Cancel = false; e.BlockTouchInputThreshold = 0; return; } } CaptureWindow = GetWindowFromPoint(e.FirstCapturedPoints.FirstOrDefault()); var applicationFromWindow = GetApplicationFromWindow(CaptureWindow); int maxThreshold = 0; bool?limitNumberFlag = null; foreach (IApplication app in applicationFromWindow) { UserApplication userApplication = app as UserApplication; if (userApplication != null) { maxThreshold = userApplication.BlockTouchInputThreshold > maxThreshold ? userApplication.BlockTouchInputThreshold : maxThreshold; //Got UserApplication if (limitNumberFlag == null) { limitNumberFlag = e.Points.Count < userApplication.LimitNumberOfFingers; } else { limitNumberFlag |= e.Points.Count < userApplication.LimitNumberOfFingers; } } IgnoredApplication ignoredApplication = app as IgnoredApplication; if (ignoredApplication != null && ignoredApplication.IsEnabled) { e.Cancel = true; return; } } e.Cancel = limitNumberFlag ?? e.Points.Count == 1; e.BlockTouchInputThreshold = maxThreshold; }
protected void TouchCapture_CaptureStarted(object sender, PointsCapturedEventArgs e) { var touchCapture = (ITouchCapture)sender; if (touchCapture.Mode == CaptureMode.Training) { return; } if (Environment.OSVersion.Version.Major == 6) { IntPtr hwndCharmBar = FindWindow("NativeHWNDHost", "Charm Bar"); var window = SystemWindow.FromPointEx(SystemWindow.DesktopWindow.Rectangle.Right - 1, 1, true, true); if (window != null && window.HWnd.Equals(hwndCharmBar)) { e.Cancel = e.InterceptTouchInput = false; return; } } CaptureWindow = GetWindowFromPoint(e.LastCapturedPoints.FirstOrDefault()); IApplication[] applicationFromWindow = GetApplicationFromWindow(CaptureWindow); foreach (IApplication app in applicationFromWindow) { e.InterceptTouchInput |= (app is UserApplication && (app as UserApplication).InterceptTouchInput); if ((app is IgnoredApplication) && (app as IgnoredApplication).IsEnabled) { e.Cancel = true; return; } else if (e.Points.Count == 1) { e.Cancel = true; UserApplication userApplication = app as UserApplication; if (userApplication != null && userApplication.AllowSingleStroke) { e.Cancel = false; return; } } } }
public IApplication ToUserApplication(MatchUsing MatchUsing) { UserApplication userApplication = new UserApplication(); userApplication.Name = ApplicationName; userApplication.MatchUsing = MatchUsing; switch (MatchUsing) { case MatchUsing.WindowClass: userApplication.MatchString = WindowClass; break; case MatchUsing.WindowTitle: userApplication.MatchString = WindowTitle; break; case MatchUsing.ExecutableFilename: userApplication.MatchString = WindowFilename; break; } userApplication.IsRegEx = false; return userApplication; }
private bool SaveApplication() { string matchString = MatchStringTextBox.Text.Trim(); if (string.IsNullOrEmpty(matchString)) { return ShowErrorMessage( LocalizationProvider.Instance.GetTextValue("ApplicationDialog.Messages.EmptyStringTitle"), LocalizationProvider.Instance.GetTextValue("ApplicationDialog.Messages.EmptyString")); } string name; if (_isUserApp) { string groupName = GroupComboBox.Text ?? String.Empty; groupName = groupName.Trim(); name = ApplicationNameTextBox.Text.Trim(); if (string.IsNullOrWhiteSpace(name)) { return ShowErrorMessage( LocalizationProvider.Instance.GetTextValue("ApplicationDialog.Messages.NoApplicationNameTitle"), LocalizationProvider.Instance.GetTextValue("ApplicationDialog.Messages.NoApplicationName")); } if (_currentApplication == null) { //Add new UserApplication var sameMatchApplications = ApplicationManager.Instance.FindMatchApplications<UserApplication>(matchUsingRadio.MatchUsing, matchString); if (sameMatchApplications.Length != 0) { string sameApp = sameMatchApplications.Aggregate<IApplication, string>(null, (current, app) => current + (app.Name + " ")); return ShowErrorMessage(LocalizationProvider.Instance.GetTextValue("ApplicationDialog.Messages.StringConflictTitle"), string.Format(LocalizationProvider.Instance.GetTextValue("ApplicationDialog.Messages.StringConflict"), matchString, sameApp)); } if (ApplicationManager.Instance.ApplicationExists(name)) return ShowErrorMessage( LocalizationProvider.Instance.GetTextValue("ApplicationDialog.Messages.AppExistsTitle"), LocalizationProvider.Instance.GetTextValue("ApplicationDialog.Messages.AppExists")); var newApplication = new UserApplication { InterceptTouchInput = InterceptTouchInputCheckBox.IsChecked.Value, AllowSingleStroke = AllowSingleCheckBox.IsChecked.Value, Name = name, Group = groupName, MatchString = matchString, MatchUsing = matchUsingRadio.MatchUsing, IsRegEx = RegexCheckBox.IsChecked.Value }; ApplicationManager.Instance.AddApplication(newApplication); UserApplicationChanged?.Invoke(this, new ApplicationChangedEventArgs(newApplication)); } else { var sameMatchApplications = ApplicationManager.Instance.FindMatchApplications<UserApplication>(matchUsingRadio.MatchUsing, matchString, _currentApplication.Name); if (sameMatchApplications.Length != 0) { string sameApp = sameMatchApplications.Aggregate<IApplication, string>(null, (current, app) => current + (app.Name + " ")); return ShowErrorMessage( LocalizationProvider.Instance.GetTextValue("ApplicationDialog.Messages.StringConflictTitle"), string.Format(LocalizationProvider.Instance.GetTextValue("ApplicationDialog.Messages.StringConflict"), matchString, sameApp)); } if (!name.Equals(_currentApplication.Name) && ApplicationManager.Instance.ApplicationExists(name)) { return ShowErrorMessage( LocalizationProvider.Instance.GetTextValue("ApplicationDialog.Messages.AppExistsTitle"), LocalizationProvider.Instance.GetTextValue("ApplicationDialog.Messages.AppExists")); } _currentApplication.Name = name; _currentApplication.Group = groupName; _currentApplication.MatchUsing = matchUsingRadio.MatchUsing; _currentApplication.MatchString = matchString; _currentApplication.IsRegEx = RegexCheckBox.IsChecked.Value; ((UserApplication)_currentApplication).AllowSingleStroke = AllowSingleCheckBox.IsChecked.Value; ((UserApplication)_currentApplication).InterceptTouchInput = InterceptTouchInputCheckBox.IsChecked.Value; UserApplicationChanged?.Invoke(this, new ApplicationChangedEventArgs(_currentApplication)); } } else { name = matchUsingRadio.MatchUsing + "$" + matchString; if (_currentApplication != null) { if (!name.Equals(_currentApplication.Name) && ApplicationManager.Instance.GetIgnoredApplications().Any(app => app.Name.Equals(name))) { return ShowErrorMessage( LocalizationProvider.Instance.GetTextValue("ApplicationDialog.Messages.IgnoredAppExistsTitle"), LocalizationProvider.Instance.GetTextValue("ApplicationDialog.Messages.IgnoredAppExists")); } ApplicationManager.Instance.RemoveApplication(_currentApplication); } else if (ApplicationManager.Instance.GetIgnoredApplications().Any(app => app.Name.Equals(name))) { return ShowErrorMessage( LocalizationProvider.Instance.GetTextValue("ApplicationDialog.Messages.IgnoredAppExistsTitle"), LocalizationProvider.Instance.GetTextValue("ApplicationDialog.Messages.IgnoredAppExists")); } ApplicationManager.Instance.AddApplication(new IgnoredApplication(name, matchUsingRadio.MatchUsing, matchString, RegexCheckBox.IsChecked.Value, true)); IgnoredApplicationsChanged?.Invoke(this, EventArgs.Empty); } ApplicationManager.Instance.SaveApplications(); return true; }