Exemple #1
0
        public InputService(
            IKeyStateService keyStateService,
            IDictionaryService dictionaryService,
            IAudioService audioService,
            ICapturingStateManager capturingStateManager,
            IPointSource pointSource,
            ITriggerSource eyeGestureTriggerSource,
            ITriggerSource keySelectionTriggerSource,
            ITriggerSource pointSelectionTriggerSource)
        {
            this.keyStateService             = keyStateService;
            this.dictionaryService           = dictionaryService;
            this.audioService                = audioService;
            this.capturingStateManager       = capturingStateManager;
            this.pointSource                 = pointSource;
            this.eyeGestureTriggerSource     = eyeGestureTriggerSource;
            this.keySelectionTriggerSource   = keySelectionTriggerSource;
            this.pointSelectionTriggerSource = pointSelectionTriggerSource;

            //Fixation key triggers also need the enabled state info and override times
            if (keySelectionTriggerSource is IFixationTriggerSource fixationTrigger)
            {
                fixationTrigger.KeyEnabledStates = keyStateService.KeyEnabledStates;
                OverrideTimesByKey = fixationTrigger.OverrideTimesByKey;
            }
        }
        public MainWindow(
            IAudioService audioService,
            IDictionaryService dictionaryService,
            IInputService inputService,
            IKeyStateService keyStateService)
        {
            InitializeComponent();

            this.audioService      = audioService;
            this.dictionaryService = dictionaryService;
            this.inputService      = inputService;
            this.keyStateService   = keyStateService;

            defaultPointSource    = inputService.PointSource;
            manualModePointSource = new MousePositionSource(Settings.Default.PointTtl)
            {
                State = RunningStates.Paused
            };

            managementWindowRequest        = new InteractionRequest <NotificationWithServicesAndState>();
            managementWindowRequestCommand = new DelegateCommand(RequestManagementWindow);
            toggleManualModeCommand        = new DelegateCommand(ToggleManualMode, () => !(defaultPointSource is MousePositionSource));
            quitCommand    = new DelegateCommand(Quit);
            backCommand    = new DelegateCommand(Back);
            restartCommand = new DelegateCommand(Restart);

            //Setup key binding (Alt+M and Shift+Alt+M) to open settings
            InputBindings.Add(new KeyBinding
            {
                Command   = managementWindowRequestCommand,
                Modifiers = ModifierKeys.Alt,
                Key       = Key.M
            });
            InputBindings.Add(new KeyBinding
            {
                Command   = managementWindowRequestCommand,
                Modifiers = ModifierKeys.Shift | ModifierKeys.Alt,
                Key       = Key.M
            });

            //Setup key binding (Alt+Enter and Shift+Alt+Enter) to open settings
            InputBindings.Add(new KeyBinding
            {
                Command   = toggleManualModeCommand,
                Modifiers = ModifierKeys.Alt,
                Key       = Key.Enter
            });
            InputBindings.Add(new KeyBinding
            {
                Command   = toggleManualModeCommand,
                Modifiers = ModifierKeys.Shift | ModifierKeys.Alt,
                Key       = Key.Enter
            });

            Title = string.Format(Properties.Resources.WINDOW_TITLE, DiagnosticInfo.AssemblyVersion);

            //Set the window size to 0x0 as this prevents a flicker where OptiKey would be displayed in the default position and then repositioned
            Width  = 0;
            Height = 0;
        }
Exemple #3
0
        public KeyEnabledStates(
            IKeyStateService keyStateService,
            ISuggestionStateService suggestionService,
            ICapturingStateManager capturingStateManager,
            ILastMouseActionStateManager lastMouseActionStateManager,
            ICalibrationService calibrationService)
        {
            this.keyStateService             = keyStateService;
            this.suggestionService           = suggestionService;
            this.capturingStateManager       = capturingStateManager;
            this.lastMouseActionStateManager = lastMouseActionStateManager;
            this.calibrationService          = calibrationService;

            suggestionService.OnPropertyChanges(ss => ss.Suggestions).Subscribe(_ => NotifyStateChanged());
            suggestionService.OnPropertyChanges(ss => ss.SuggestionsPage).Subscribe(_ => NotifyStateChanged());
            suggestionService.OnPropertyChanges(ss => ss.SuggestionsPerPage).Subscribe(_ => NotifyStateChanged());

            keyStateService.OnPropertyChanges(kss => kss.SimulateKeyStrokes).Subscribe(_ => NotifyStateChanged());
            keyStateService.KeyDownStates[KeyValues.MouseLeftDownUpKey].OnPropertyChanges(np => np.Value).Subscribe(_ => NotifyStateChanged());
            keyStateService.KeyDownStates[KeyValues.MouseMiddleDownUpKey].OnPropertyChanges(np => np.Value).Subscribe(_ => NotifyStateChanged());
            keyStateService.KeyDownStates[KeyValues.MouseRightDownUpKey].OnPropertyChanges(np => np.Value).Subscribe(_ => NotifyStateChanged());
            keyStateService.KeyDownStates[KeyValues.SleepKey].OnPropertyChanges(np => np.Value).Subscribe(_ => NotifyStateChanged());

            KeyValues.KeysWhichPreventTextCaptureIfDownOrLocked.ForEach(kv =>
                                                                        keyStateService.KeyDownStates[kv].OnPropertyChanges(np => np.Value).Subscribe(_ => NotifyStateChanged()));

            capturingStateManager.OnPropertyChanges(csm => csm.CapturingMultiKeySelection).Subscribe(_ => NotifyStateChanged());

            lastMouseActionStateManager.OnPropertyChanges(lmasm => lmasm.LastMouseActionExists).Subscribe(_ => NotifyStateChanged());

            Settings.Default.OnPropertyChanges(s => s.MultiKeySelectionEnabled).Subscribe(_ => NotifyStateChanged());
            Settings.Default.OnPropertyChanges(s => s.MainWindowState).Subscribe(_ => NotifyStateChanged());
            Settings.Default.OnPropertyChanges(s => s.MainWindowDockPosition).Subscribe(_ => NotifyStateChanged());
        }
        public InputService(
            IKeyStateService keyStateService,
            IDictionaryService dictionaryService,
            IAudioService audioService,
            ICapturingStateManager capturingStateManager,
            IPointSource pointSource,
            ITriggerSource keySelectionTriggerSource,
            ITriggerSource pointSelectionTriggerSource)
        {
            this.keyStateService             = keyStateService;
            this.dictionaryService           = dictionaryService;
            this.audioService                = audioService;
            this.capturingStateManager       = capturingStateManager;
            this.pointSource                 = pointSource;
            this.keySelectionTriggerSource   = keySelectionTriggerSource;
            this.pointSelectionTriggerSource = pointSelectionTriggerSource;

            //Fixation key triggers also need the enabled state info
            var fixationTrigger = keySelectionTriggerSource as IFixationTriggerSource;

            if (fixationTrigger != null)
            {
                fixationTrigger.KeyEnabledStates = keyStateService.KeyEnabledStates;
            }
        }
Exemple #5
0
        public MainWindow(
            IAudioService audioService,
            IDictionaryService dictionaryService,
            IInputService inputService,
            IKeyStateService keyStateService)
        {
            InitializeComponent();

            this.audioService = audioService;
            this.dictionaryService = dictionaryService;
            this.inputService = inputService;
            this.keyStateService = keyStateService;

            managementWindowRequest = new InteractionRequest<NotificationWithServicesAndState>();
            managementWindowRequestCommand = new DelegateCommand(RequestManagementWindow);
            quitCommand = new DelegateCommand(Quit);

            //Setup key binding (Alt-M and Shift-Alt-M) to open settings
            InputBindings.Add(new KeyBinding
            {
                Command = managementWindowRequestCommand,
                Modifiers = ModifierKeys.Alt,
                Key = Key.M
            });
            InputBindings.Add(new KeyBinding
            {
                Command = managementWindowRequestCommand,
                Modifiers = ModifierKeys.Shift | ModifierKeys.Alt,
                Key = Key.M
            });

            Title = string.Format(Properties.Resources.WINDOW_TITLE, DiagnosticInfo.AssemblyVersion);
        }
Exemple #6
0
        public MainViewModel(
            IAudioService audioService,
            ICalibrationService calibrationService,
            IDictionaryService dictionaryService,
            IKeyStateService keyStateService,
            ISuggestionStateService suggestionService,
            ICapturingStateManager capturingStateManager,
            ILastMouseActionStateManager lastMouseActionStateManager,
            IInputService inputService,
            IKeyboardOutputService keyboardOutputService,
            IMouseOutputService mouseOutputService,
            IWindowManipulationService mainWindowManipulationService,
            List<INotifyErrors> errorNotifyingServices)
        {
            this.audioService = audioService;
            this.calibrationService = calibrationService;
            this.dictionaryService = dictionaryService;
            this.keyStateService = keyStateService;
            this.suggestionService = suggestionService;
            this.capturingStateManager = capturingStateManager;
            this.lastMouseActionStateManager = lastMouseActionStateManager;
            this.inputService = inputService;
            this.keyboardOutputService = keyboardOutputService;
            this.mouseOutputService = mouseOutputService;
            this.mainWindowManipulationService = mainWindowManipulationService;
            this.errorNotifyingServices = errorNotifyingServices;

            calibrateRequest = new InteractionRequest<NotificationWithCalibrationResult>();
            SelectionMode = SelectionModes.Key;

            InitialiseKeyboard(mainWindowManipulationService);
            AttachScratchpadEnabledListener();
            AttachKeyboardSupportsCollapsedDockListener(mainWindowManipulationService);
            AttachKeyboardSupportsSimulateKeyStrokesListener();
        }
Exemple #7
0
        public MainWindow(
            IAudioService audioService,
            IDictionaryService dictionaryService,
            IInputService inputService,
            IKeyStateService keyStateService)
        {
            InitializeComponent();

            this.audioService      = audioService;
            this.dictionaryService = dictionaryService;
            this.inputService      = inputService;
            this.keyStateService   = keyStateService;

            managementWindowRequest        = new InteractionRequest <NotificationWithServicesAndState>();
            managementWindowRequestCommand = new DelegateCommand(RequestManagementWindow);
            quitCommand = new DelegateCommand(Quit);

            //Setup key binding (Alt-M and Shift-Alt-M) to open settings
            InputBindings.Add(new KeyBinding
            {
                Command   = managementWindowRequestCommand,
                Modifiers = ModifierKeys.Alt,
                Key       = Key.M
            });
            InputBindings.Add(new KeyBinding
            {
                Command   = managementWindowRequestCommand,
                Modifiers = ModifierKeys.Shift | ModifierKeys.Alt,
                Key       = Key.M
            });

            Title = string.Format(Properties.Resources.WINDOW_TITLE, DiagnosticInfo.AssemblyVersion);
        }
Exemple #8
0
 public static void ReleaseKeysOnApplicationExit(IKeyStateService keyStateService, IPublishService publishService)
 {
     if (keyStateService.SimulateKeyStrokes)
     {
         publishService.ReleaseAllDownKeys();
     }
 }
 public DynamicKeyboard(Action backAction,
                        IWindowManipulationService windowManipulationService,
                        IKeyStateService keyStateService,
                        IInputService inputService,
                        IAudioService audioService,
                        Func <string, string, NotificationTypes, Action, bool> raiseToastNotification,
                        string link,
                        Dictionary <Models.KeyValue, Enums.KeyDownStates> overrideKeyStates = null,
                        bool persistNewState    = false,
                        string windowState      = "",
                        string position         = "",
                        string dockSize         = "",
                        string width            = "",
                        string height           = "",
                        string horizontalOffset = "",
                        string verticalOffset   = "") : base(backAction)
 {
     this.windowManipulationService = windowManipulationService;
     this.link                   = link;
     this.keyStateService        = keyStateService;
     this.inputService           = inputService;
     this.audioService           = audioService;
     this.raiseToastNotification = raiseToastNotification;
     this.overrideKeyStates      = overrideKeyStates;
     this.persistNewState        = persistNewState;
     this.windowState            = windowState;
     this.position               = position;
     this.dockSize               = dockSize;
     this.width                  = width;
     this.height                 = height;
     this.horizontalOffset       = horizontalOffset;
     this.verticalOffset         = verticalOffset;
 }
        public KeyEnabledStates(
            IKeyStateService keyStateService, 
            ISuggestionStateService suggestionService,
            ICapturingStateManager capturingStateManager,
            ILastMouseActionStateManager lastMouseActionStateManager,
            ICalibrationService calibrationService)
        {
            this.keyStateService = keyStateService;
            this.suggestionService = suggestionService;
            this.capturingStateManager = capturingStateManager;
            this.lastMouseActionStateManager = lastMouseActionStateManager;
            this.calibrationService = calibrationService;

            suggestionService.OnPropertyChanges(ss => ss.Suggestions).Subscribe(_ => NotifyStateChanged());
            suggestionService.OnPropertyChanges(ss => ss.SuggestionsPage).Subscribe(_ => NotifyStateChanged());
            suggestionService.OnPropertyChanges(ss => ss.SuggestionsPerPage).Subscribe(_ => NotifyStateChanged());

            keyStateService.OnPropertyChanges(kss => kss.SimulateKeyStrokes).Subscribe(_ => NotifyStateChanged());
            keyStateService.KeyDownStates[KeyValues.MouseLeftDownUpKey].OnPropertyChanges(np => np.Value).Subscribe(_ => NotifyStateChanged());
            keyStateService.KeyDownStates[KeyValues.MouseMiddleDownUpKey].OnPropertyChanges(np => np.Value).Subscribe(_ => NotifyStateChanged());
            keyStateService.KeyDownStates[KeyValues.MouseRightDownUpKey].OnPropertyChanges(np => np.Value).Subscribe(_ => NotifyStateChanged());
            keyStateService.KeyDownStates[KeyValues.SleepKey].OnPropertyChanges(np => np.Value).Subscribe(_ => NotifyStateChanged());

            KeyValues.KeysWhichPreventTextCaptureIfDownOrLocked.ForEach(kv =>
                keyStateService.KeyDownStates[kv].OnPropertyChanges(np => np.Value).Subscribe(_ => NotifyStateChanged()));

            capturingStateManager.OnPropertyChanges(csm => csm.CapturingMultiKeySelection).Subscribe(_ => NotifyStateChanged());

            lastMouseActionStateManager.OnPropertyChanges(lmasm => lmasm.LastMouseActionExists).Subscribe(_ => NotifyStateChanged());

            Settings.Default.OnPropertyChanges(s => s.MultiKeySelectionEnabled).Subscribe(_ => NotifyStateChanged());
            Settings.Default.OnPropertyChanges(s => s.MainWindowState).Subscribe(_ => NotifyStateChanged());
            Settings.Default.OnPropertyChanges(s => s.MainWindowDockPosition).Subscribe(_ => NotifyStateChanged());
        }
        public MainViewModel(
            IAudioService audioService,
            ICalibrationService calibrationService,
            IDictionaryService dictionaryService,
            IKeyStateService keyStateService,
            ISuggestionStateService suggestionService,
            ICapturingStateManager capturingStateManager,
            ILastMouseActionStateManager lastMouseActionStateManager,
            IInputService inputService,
            IKeyboardOutputService keyboardOutputService,
            IMouseOutputService mouseOutputService,
            IWindowManipulationService mainWindowManipulationService,
            List <INotifyErrors> errorNotifyingServices)
        {
            this.audioService                  = audioService;
            this.calibrationService            = calibrationService;
            this.dictionaryService             = dictionaryService;
            this.keyStateService               = keyStateService;
            this.suggestionService             = suggestionService;
            this.capturingStateManager         = capturingStateManager;
            this.lastMouseActionStateManager   = lastMouseActionStateManager;
            this.inputService                  = inputService;
            this.keyboardOutputService         = keyboardOutputService;
            this.mouseOutputService            = mouseOutputService;
            this.mainWindowManipulationService = mainWindowManipulationService;
            this.errorNotifyingServices        = errorNotifyingServices;

            calibrateRequest = new InteractionRequest <NotificationWithCalibrationResult>();
            SelectionMode    = SelectionModes.Key;

            InitialiseKeyboard(mainWindowManipulationService);
            AttachScratchpadEnabledListener();
            AttachKeyboardSupportsCollapsedDockListener(mainWindowManipulationService);
            AttachKeyboardSupportsSimulateKeyStrokesListener();
        }
Exemple #12
0
 public DynamicKeyboard(Action backAction, IWindowManipulationService windowManipulationService,
                        IKeyStateService keyStateService, string link)
     : base(backAction)
 {
     this.windowManipulationService = windowManipulationService;
     this.link            = link;
     this.keyStateService = keyStateService;
 }
Exemple #13
0
 public DynamicKeyboard(Action backAction,
                        IKeyStateService keyStateService,
                        string link,
                        Dictionary <Models.KeyValue, Enums.KeyDownStates> overrideKeyStates = null) : base(backAction)
 {
     this.link              = link;
     this.keyStateService   = keyStateService;
     this.overrideKeyStates = overrideKeyStates;
 }
Exemple #14
0
 private void ReleaseKeysOnApplicationExit(IKeyStateService keyStateService, IPublishService publishService)
 {
     Current.Exit += (o, args) =>
     {
         if (keyStateService.SimulateKeyStrokes)
         {
             publishService.ReleaseAllDownKeys();
         }
     };
 }
Exemple #15
0
        public MainWindow(
            IAudioService audioService,
            IDictionaryService dictionaryService,
            IInputService inputService,
            IKeyStateService keyStateService)
        {
            InitializeComponent();

            this.audioService      = audioService;
            this.dictionaryService = dictionaryService;
            this.inputService      = inputService;
            this.keyStateService   = keyStateService;

            defaultPointSource    = inputService.PointSource;
            manualModePointSource = new MousePositionSource(Settings.Default.PointTtl)
            {
                State = RunningStates.Paused
            };

            managementWindowRequest        = new InteractionRequest <NotificationWithServicesAndState>();
            managementWindowRequestCommand = new DelegateCommand(RequestManagementWindow);
            toggleManualModeCommand        = new DelegateCommand(ToggleManualMode);
            quitCommand = new DelegateCommand(Quit);

            //Setup key binding (Alt+M and Shift+Alt+M) to open settings
            InputBindings.Add(new KeyBinding
            {
                Command   = managementWindowRequestCommand,
                Modifiers = ModifierKeys.Alt,
                Key       = Key.M
            });
            InputBindings.Add(new KeyBinding
            {
                Command   = managementWindowRequestCommand,
                Modifiers = ModifierKeys.Shift | ModifierKeys.Alt,
                Key       = Key.M
            });

            //Setup key binding (Alt+Enter and Shift+Alt+Enter) to open settings
            InputBindings.Add(new KeyBinding
            {
                Command   = toggleManualModeCommand,
                Modifiers = ModifierKeys.Alt,
                Key       = Key.Enter
            });
            InputBindings.Add(new KeyBinding
            {
                Command   = toggleManualModeCommand,
                Modifiers = ModifierKeys.Shift | ModifierKeys.Alt,
                Key       = Key.Enter
            });

            Title = string.Format(Properties.Resources.WINDOW_TITLE, DiagnosticInfo.AssemblyVersion);
        }
 public DynamicKeyboard(Action backAction,
                        IWindowManipulationService windowManipulationService,
                        IKeyStateService keyStateService,
                        IInputService inputService,
                        IAudioService audioService,
                        Func <string, string, NotificationTypes, Action, bool> raiseToastNotification,
                        string link) : base(backAction)
 {
     this.windowManipulationService = windowManipulationService;
     this.link                   = link;
     this.keyStateService        = keyStateService;
     this.inputService           = inputService;
     this.audioService           = audioService;
     this.raiseToastNotification = raiseToastNotification;
 }
Exemple #17
0
        public MainViewModel(IAudioService audioService, IInputService inputService,
                             IKeyStateService keyStateService, List <INotifyErrors> errorNotifyingServices,
                             Dictionary <char, string> pronunciation)
        {
            this.audioService           = audioService;
            this.inputService           = inputService;
            this.keyStateService        = keyStateService;
            this.errorNotifyingServices = errorNotifyingServices;
            this.pronunciation          = pronunciation;

            managementWindowRequest        = new InteractionRequest <NotificationWithAudioService>();
            managementWindowRequestCommand = new DelegateCommand(RequestManagementWindow);
            quitRequestCommand             = new DelegateCommand(Quit);

            Settings.Default.OnPropertyChanges(s => s.QuizFile).Subscribe(_ => OnPropertyChanged(() => QuizFileName));

            StartQuizCommand = new DelegateCommand(StartQuiz);
        }
Exemple #18
0
        public MainViewModel(
            IAudioService audioService,
            ICalibrationService calibrationService,
            IDictionaryService dictionaryService,
            IKeyStateService keyStateService,
            ISuggestionStateService suggestionService,
            ICapturingStateManager capturingStateManager,
            ILastMouseActionStateManager lastMouseActionStateManager,
            IInputService inputService,
            IKeyboardOutputService keyboardOutputService,
            IMouseOutputService mouseOutputService,
            IWindowManipulationService mainWindowManipulationService,
            List <INotifyErrors> errorNotifyingServices)
        {
            this.audioService                  = audioService;
            this.calibrationService            = calibrationService;
            this.dictionaryService             = dictionaryService;
            this.keyStateService               = keyStateService;
            this.suggestionService             = suggestionService;
            this.capturingStateManager         = capturingStateManager;
            this.lastMouseActionStateManager   = lastMouseActionStateManager;
            this.inputService                  = inputService;
            this.keyboardOutputService         = keyboardOutputService;
            this.mouseOutputService            = mouseOutputService;
            this.mainWindowManipulationService = mainWindowManipulationService;
            this.errorNotifyingServices        = errorNotifyingServices;

            calibrateRequest = new InteractionRequest <NotificationWithCalibrationResult>();
            SelectionMode    = SelectionModes.Key;

            this.translationService = new TranslationService(new HttpClient());

            SetupInputServiceEventHandlers();
            InitialiseKeyboard(mainWindowManipulationService);
            AttachScratchpadEnabledListener();
            AttachKeyboardSupportsCollapsedDockListener(mainWindowManipulationService);
            AttachKeyboardSupportsSimulateKeyStrokesListener();
            AttachKeyboardSupportsMultiKeySelectionListener();
            ShowCrosshair = Settings.Default.GazeIndicatorStyle == GazeIndicatorStyles.Crosshair ||
                            Settings.Default.GazeIndicatorStyle == GazeIndicatorStyles.Scope;
            ShowMonical = Settings.Default.GazeIndicatorStyle == GazeIndicatorStyles.Monical ||
                          Settings.Default.GazeIndicatorStyle == GazeIndicatorStyles.Scope;
        }
        public KeyboardOutputService(
            IKeyStateService keyStateService,
            ISuggestionStateService suggestionService,
            IPublishService publishService,
            IDictionaryService dictionaryService,
            Action <KeyValue> fireKeySelectionEvent)
        {
            this.keyStateService       = keyStateService;
            this.suggestionService     = suggestionService;
            this.publishService        = publishService;
            this.dictionaryService     = dictionaryService;
            this.fireKeySelectionEvent = fireKeySelectionEvent;

            ReactToSimulateKeyStrokesChanges();
            ReactToShiftStateChanges();
            ReactToPublishableKeyDownStateChanges();
            ReactToKeyboardIsShiftAwareChanges();
            ReactToSuppressAutoCapitaliseIntelligentlyChanges();
            AutoPressShiftIfAppropriate();
        }
        public KeyboardOutputService(
            IKeyStateService keyStateService,
            ISuggestionStateService suggestionService,
            IPublishService publishService,
            IDictionaryService dictionaryService,
            Action<KeyValue> fireKeySelectionEvent)
        {
            this.keyStateService = keyStateService;
            this.suggestionService = suggestionService;
            this.publishService = publishService;
            this.dictionaryService = dictionaryService;
            this.fireKeySelectionEvent = fireKeySelectionEvent;

            ReactToSimulateKeyStrokesChanges();
            ReactToShiftStateChanges();
            ReactToPublishableKeyDownStateChanges();
            ReactToKeyboardIsShiftAwareChanges();
            ReactToSuppressAutoCapitaliseIntelligentlyChanges();
            AutoPressShiftIfAppropriate();
        }
Exemple #21
0
        public MainWindow(
            IAudioService audioService,
            IDictionaryService dictionaryService,
            IInputService inputService,
            IKeyStateService keyStateService)
        {
            InitializeComponent();

            notifyIcon                   = new System.Windows.Forms.NotifyIcon();
            notifyIcon.Icon              = new System.Drawing.Icon("../../Resources/Icons/Main.ico");
            notifyIcon.MouseDoubleClick +=
                new System.Windows.Forms.MouseEventHandler
                    (mynotifyIcon_Close);

            this.audioService      = audioService;
            this.dictionaryService = dictionaryService;
            this.inputService      = inputService;
            this.keyStateService   = keyStateService;

            managementWindowRequest        = new InteractionRequest <NotificationWithServicesAndState>();
            managementWindowRequestCommand = new DelegateCommand(RequestManagementWindow);
            quitCommand = new DelegateCommand(Quit);

            //Setup key binding (Alt-M and Shift-Alt-M) to open settings
            InputBindings.Add(new KeyBinding
            {
                Command   = managementWindowRequestCommand,
                Modifiers = ModifierKeys.Alt,
                Key       = Key.M
            });
            InputBindings.Add(new KeyBinding
            {
                Command   = managementWindowRequestCommand,
                Modifiers = ModifierKeys.Shift | ModifierKeys.Alt,
                Key       = Key.M
            });

            Title = string.Format(Properties.Resources.WINDOW_TITLE, DiagnosticInfo.AssemblyVersion);
        }
        public static Action ReleaseModifiers(this IKeyStateService keyStateService, ILog log)
        {
            var lastLeftShiftValue = keyStateService.KeyDownStates[KeyValues.LeftShiftKey].Value;
            var lastLeftCtrlValue  = keyStateService.KeyDownStates[KeyValues.LeftCtrlKey].Value;
            var lastLeftWinValue   = keyStateService.KeyDownStates[KeyValues.LeftWinKey].Value;
            var lastLeftAltValue   = keyStateService.KeyDownStates[KeyValues.LeftAltKey].Value;

            log.InfoFormat("Releasing modifiers (shift:{0}, ctrl:{1}, win:{2}, alt:{3})",
                           lastLeftShiftValue, lastLeftCtrlValue, lastLeftWinValue, lastLeftAltValue);

            keyStateService.KeyDownStates[KeyValues.LeftShiftKey].Value = KeyDownStates.Up;
            keyStateService.KeyDownStates[KeyValues.LeftCtrlKey].Value  = KeyDownStates.Up;
            keyStateService.KeyDownStates[KeyValues.LeftWinKey].Value   = KeyDownStates.Up;
            keyStateService.KeyDownStates[KeyValues.LeftAltKey].Value   = KeyDownStates.Up;
            return(() =>
            {
                log.InfoFormat("Restoring modifiers (shift:{0}, ctrl:{1}, win:{2}, alt:{3})",
                               lastLeftShiftValue, lastLeftCtrlValue, lastLeftWinValue, lastLeftAltValue);
                keyStateService.KeyDownStates[KeyValues.LeftShiftKey].Value = lastLeftShiftValue;
                keyStateService.KeyDownStates[KeyValues.LeftCtrlKey].Value = lastLeftCtrlValue;
                keyStateService.KeyDownStates[KeyValues.LeftWinKey].Value = lastLeftWinValue;
                keyStateService.KeyDownStates[KeyValues.LeftAltKey].Value = lastLeftAltValue;
            });
        }
Exemple #23
0
        public InputService(
            IKeyStateService keyStateService,
            IDictionaryService dictionaryService,
            IAudioService audioService,
            ICapturingStateManager capturingStateManager,
            IPointSource pointSource,
            ITriggerSource keySelectionTriggerSource,
            ITriggerSource pointSelectionTriggerSource)
        {
            this.keyStateService = keyStateService;
            this.dictionaryService = dictionaryService;
            this.audioService = audioService;
            this.capturingStateManager = capturingStateManager;
            this.pointSource = pointSource;
            this.keySelectionTriggerSource = keySelectionTriggerSource;
            this.pointSelectionTriggerSource = pointSelectionTriggerSource;

            //Fixation key triggers also need the enabled state info
            var fixationTrigger = keySelectionTriggerSource as IFixationTriggerSource;
            if (fixationTrigger != null)
            {
                fixationTrigger.KeyEnabledStates = keyStateService.KeyEnabledStates;
            }
        }
Exemple #24
0
 private static void ReleaseKeysOnApplicationExit(IKeyStateService keyStateService, IPublishService publishService)
 {
     Current.Exit += (o, args) =>
     {
         if (keyStateService.SimulateKeyStrokes)
         {
             publishService.ReleaseAllDownKeys();
         }
     };
 }
Exemple #25
0
        public MainWindow(
            IAudioService audioService,
            IDictionaryService dictionaryService,
            IInputService inputService,
            IKeyStateService keyStateService)
        {
            InitializeComponent();

            this.audioService      = audioService;
            this.dictionaryService = dictionaryService;
            this.inputService      = inputService;
            this.keyStateService   = keyStateService;

            defaultPointSource    = inputService.PointSource;
            manualModePointSource = new MousePositionSource(Settings.Default.PointTtl)
            {
                State = RunningStates.Paused
            };

            managementWindowRequest        = new InteractionRequest <NotificationWithServicesAndState>();
            managementWindowRequestCommand = new DelegateCommand(RequestManagementWindow);
            toggleManualModeCommand        = new DelegateCommand(ToggleManualMode, () => !(defaultPointSource is MousePositionSource));
            quitCommand    = new DelegateCommand(Quit);
            backCommand    = new DelegateCommand(Back);
            restartCommand = new DelegateCommand(Restart);

            //Setup key binding (Alt+M and Shift+Alt+M) to open settings
            InputBindings.Add(new KeyBinding
            {
                Command   = managementWindowRequestCommand,
                Modifiers = ModifierKeys.Alt,
                Key       = Key.M
            });
            InputBindings.Add(new KeyBinding
            {
                Command   = managementWindowRequestCommand,
                Modifiers = ModifierKeys.Shift | ModifierKeys.Alt,
                Key       = Key.M
            });

            //Setup key binding (Alt+Enter and Shift+Alt+Enter) to open settings
            InputBindings.Add(new KeyBinding
            {
                Command   = toggleManualModeCommand,
                Modifiers = ModifierKeys.Alt,
                Key       = Key.Enter
            });
            InputBindings.Add(new KeyBinding
            {
                Command   = toggleManualModeCommand,
                Modifiers = ModifierKeys.Shift | ModifierKeys.Alt,
                Key       = Key.Enter
            });

            Title = string.Format(Properties.Resources.WINDOW_TITLE, DiagnosticInfo.AssemblyVersion);

            //Set the window size to 0x0 as this prevents a flicker where OptiKey would be displayed in the default position and then repositioned
            Width  = 0;
            Height = 0;

            this.Closing += (sender, args) =>
            {
                //https://stackoverflow.com/questions/26863458/handle-the-close-event-via-task-bar
                Log.Info("Main window closing event detected. In some circumstances, such as closing OptiKey from the taskbar when a background thread is running, OptiKey will not close and instead become a background process. Forcing a full shutdown.");
                Application.Current.Shutdown();
            };
        }
Exemple #26
0
        private IInputService CreateInputService(
            IKeyStateService keyStateService,
            IDictionaryService dictionaryService,
            IAudioService audioService,
            ICalibrationService calibrationService,
            ICapturingStateManager capturingStateManager,
            List <INotifyErrors> errorNotifyingServices)
        {
            Log.Info("Creating InputService.");

            //Instantiate point source
            IPointSource pointSource;

            switch (Settings.Default.PointsSource)
            {
            case PointsSources.GazeTracker:
                pointSource = new GazeTrackerSource(
                    Settings.Default.PointTtl,
                    Settings.Default.GazeTrackerUdpPort,
                    new Regex(Settings.Default.GazeTrackerUdpRegex));
                break;

            case PointsSources.TheEyeTribe:
                var theEyeTribePointService = new TheEyeTribePointService();
                errorNotifyingServices.Add(theEyeTribePointService);
                pointSource = new PointServiceSource(
                    Settings.Default.PointTtl,
                    theEyeTribePointService);
                break;

            case PointsSources.TobiiEyeX:
            case PointsSources.TobiiRex:
            case PointsSources.TobiiPcEyeGo:
                var tobiiEyeXPointService       = new TobiiEyeXPointService();
                var tobiiEyeXCalibrationService = calibrationService as TobiiEyeXCalibrationService;
                if (tobiiEyeXCalibrationService != null)
                {
                    tobiiEyeXCalibrationService.EyeXHost = tobiiEyeXPointService.EyeXHost;
                }
                errorNotifyingServices.Add(tobiiEyeXPointService);
                pointSource = new PointServiceSource(
                    Settings.Default.PointTtl,
                    tobiiEyeXPointService);
                break;

            case PointsSources.MousePosition:
                pointSource = new MousePositionSource(
                    Settings.Default.PointTtl);
                break;

            default:
                throw new ArgumentException("'PointsSource' settings is missing or not recognised! Please correct and restart OptiKey.");
            }

            //Instantiate key trigger source
            ITriggerSource keySelectionTriggerSource;

            switch (Settings.Default.KeySelectionTriggerSource)
            {
            case TriggerSources.Fixations:
                keySelectionTriggerSource = new KeyFixationSource(
                    Settings.Default.KeySelectionTriggerFixationLockOnTime,
                    Settings.Default.KeySelectionTriggerFixationResumeRequiresLockOn,
                    Settings.Default.KeySelectionTriggerFixationCompleteTime,
                    Settings.Default.KeySelectionTriggerIncompleteFixationTtl,
                    pointSource.Sequence);
                break;

            case TriggerSources.KeyboardKeyDownsUps:
                keySelectionTriggerSource = new KeyboardKeyDownUpSource(
                    Settings.Default.KeySelectionTriggerKeyboardKeyDownUpKey,
                    pointSource.Sequence);
                break;

            case TriggerSources.MouseButtonDownUps:
                keySelectionTriggerSource = new MouseButtonDownUpSource(
                    Settings.Default.KeySelectionTriggerMouseDownUpButton,
                    pointSource.Sequence);
                break;

            default:
                throw new ArgumentException(
                          "'KeySelectionTriggerSource' setting is missing or not recognised! Please correct and restart OptiKey.");
            }

            //Instantiate point trigger source
            ITriggerSource pointSelectionTriggerSource;

            switch (Settings.Default.PointSelectionTriggerSource)
            {
            case TriggerSources.Fixations:
                pointSelectionTriggerSource = new PointFixationSource(
                    Settings.Default.PointSelectionTriggerFixationLockOnTime,
                    Settings.Default.PointSelectionTriggerFixationCompleteTime,
                    Settings.Default.PointSelectionTriggerLockOnRadiusInPixels,
                    Settings.Default.PointSelectionTriggerFixationRadiusInPixels,
                    pointSource.Sequence);
                break;

            case TriggerSources.KeyboardKeyDownsUps:
                pointSelectionTriggerSource = new KeyboardKeyDownUpSource(
                    Settings.Default.PointSelectionTriggerKeyboardKeyDownUpKey,
                    pointSource.Sequence);
                break;

            case TriggerSources.MouseButtonDownUps:
                pointSelectionTriggerSource = new MouseButtonDownUpSource(
                    Settings.Default.PointSelectionTriggerMouseDownUpButton,
                    pointSource.Sequence);
                break;

            default:
                throw new ArgumentException(
                          "'PointSelectionTriggerSource' setting is missing or not recognised! "
                          + "Please correct and restart OptiKey.");
            }

            var inputService = new InputService(keyStateService, dictionaryService, audioService, capturingStateManager,
                                                pointSource, keySelectionTriggerSource, pointSelectionTriggerSource);

            inputService.RequestSuspend(); //Pause it initially
            return(inputService);
        }
Exemple #27
0
        private static IInputService CreateInputService(
            IKeyStateService keyStateService,
            IDictionaryService dictionaryService,
            IAudioService audioService,
            ICalibrationService calibrationService,
            ICapturingStateManager capturingStateManager,
            List<INotifyErrors> errorNotifyingServices)
        {
            Log.Info("Creating InputService.");

            //Instantiate point source
            IPointSource pointSource;
            switch (Settings.Default.PointsSource)
            {
                case PointsSources.GazeTracker:
                    pointSource = new GazeTrackerSource(
                        Settings.Default.PointTtl,
                        Settings.Default.GazeTrackerUdpPort,
                        new Regex(GazeTrackerUdpRegex));
                    break;

                case PointsSources.TheEyeTribe:
                    var theEyeTribePointService = new TheEyeTribePointService();
                    errorNotifyingServices.Add(theEyeTribePointService);
                    pointSource = new PointServiceSource(
                        Settings.Default.PointTtl,
                        theEyeTribePointService);
                    break;

                case PointsSources.TobiiEyeX:
                case PointsSources.TobiiRex:
                case PointsSources.TobiiPcEyeGo:
                    var tobiiEyeXPointService = new TobiiEyeXPointService();
                    var tobiiEyeXCalibrationService = calibrationService as TobiiEyeXCalibrationService;
                    if (tobiiEyeXCalibrationService != null)
                    {
                        tobiiEyeXCalibrationService.EyeXHost = tobiiEyeXPointService.EyeXHost;
                    }
                    errorNotifyingServices.Add(tobiiEyeXPointService);
                    pointSource = new PointServiceSource(
                        Settings.Default.PointTtl,
                        tobiiEyeXPointService);
                    break;

                case PointsSources.MousePosition:
                    pointSource = new MousePositionSource(
                        Settings.Default.PointTtl);
                    break;

                default:
                    throw new ArgumentException("'PointsSource' settings is missing or not recognised! Please correct and restart OptiKey.");
            }

            //Instantiate key trigger source
            ITriggerSource keySelectionTriggerSource;
            switch (Settings.Default.KeySelectionTriggerSource)
            {
                case TriggerSources.Fixations:
                    keySelectionTriggerSource = new KeyFixationSource(
                       Settings.Default.KeySelectionTriggerFixationLockOnTime,
                       Settings.Default.KeySelectionTriggerFixationResumeRequiresLockOn,
                       Settings.Default.KeySelectionTriggerFixationDefaultCompleteTime,
                       Settings.Default.KeySelectionTriggerFixationCompleteTimesByIndividualKey
                        ? Settings.Default.KeySelectionTriggerFixationCompleteTimesByKeyValues
                        : null, 
                       Settings.Default.KeySelectionTriggerIncompleteFixationTtl,
                       pointSource.Sequence);
                    break;

                case TriggerSources.KeyboardKeyDownsUps:
                    keySelectionTriggerSource = new KeyboardKeyDownUpSource(
                        Settings.Default.KeySelectionTriggerKeyboardKeyDownUpKey,
                        pointSource.Sequence);
                    break;

                case TriggerSources.MouseButtonDownUps:
                    keySelectionTriggerSource = new MouseButtonDownUpSource(
                        Settings.Default.KeySelectionTriggerMouseDownUpButton,
                        pointSource.Sequence);
                    break;

                default:
                    throw new ArgumentException(
                        "'KeySelectionTriggerSource' setting is missing or not recognised! Please correct and restart OptiKey.");
            }

            //Instantiate point trigger source
            ITriggerSource pointSelectionTriggerSource;
            switch (Settings.Default.PointSelectionTriggerSource)
            {
                case TriggerSources.Fixations:
                    pointSelectionTriggerSource = new PointFixationSource(
                        Settings.Default.PointSelectionTriggerFixationLockOnTime,
                        Settings.Default.PointSelectionTriggerFixationCompleteTime,
                        Settings.Default.PointSelectionTriggerLockOnRadiusInPixels,
                        Settings.Default.PointSelectionTriggerFixationRadiusInPixels,
                        pointSource.Sequence);
                    break;

                case TriggerSources.KeyboardKeyDownsUps:
                    pointSelectionTriggerSource = new KeyboardKeyDownUpSource(
                        Settings.Default.PointSelectionTriggerKeyboardKeyDownUpKey,
                        pointSource.Sequence);
                    break;

                case TriggerSources.MouseButtonDownUps:
                    pointSelectionTriggerSource = new MouseButtonDownUpSource(
                        Settings.Default.PointSelectionTriggerMouseDownUpButton,
                        pointSource.Sequence);
                    break;

                default:
                    throw new ArgumentException(
                        "'PointSelectionTriggerSource' setting is missing or not recognised! "
                        + "Please correct and restart OptiKey.");
            }

            var inputService = new InputService(keyStateService, dictionaryService, audioService, capturingStateManager,
                pointSource, keySelectionTriggerSource, pointSelectionTriggerSource);
            inputService.RequestSuspend(); //Pause it initially
            return inputService;
        }