Exemple #1
0
        private void HandleDownEvent(InputArgs e)
        {
            var combo = new Combo(e.Input, _modifiers);
            var b     = _backspaceAction;

            _backspaceAction = null;
            // If there is an action pending for backspace, execute it.
            if (b != null && combo == Combo.Backspace)
            {
                b();
                e.Capture = true;
            }
            // Clear the stuck modifiers with the close key.
            else if (_stuckModifiers != Modifiers.None && e.Input == Env.Config.CloseKey)
            {
                e.Capture = true;
            }
            // Otherwise, if there are no modifiers needed to release, let the next hook decide what to do.
            else if (_modifiersToRelease == Modifiers.None)
            {
                var comboArgs = new ComboArgs(combo);
                _targetHook.Handle(comboArgs);
                e.Capture = comboArgs.Capture;
                // Capture a key down event that does not trigger an action when custom modifiers are active.
                e.Capture = e.Capture || _modifiers.HasCustomModifiers() && !e.Input.IsModifierKey();
            }
        }
Exemple #2
0
 public void Handle(ComboArgs e)
 {
     if (_activeMode.IsComposeMode)
     {
         HandleComposeMode(e);
     }
     else
     {
         foreach (var modeHotkey in _modeHotkeys)
         {
             if (modeHotkey.Chord.TestPosition(0, e.Combo))
             {
                 e.Capture = true;
                 try
                 {
                     modeHotkey.Action(e.Combo);
                 }
                 catch (Exception ex) when(!Helper.IsFatalException(ex))
                 {
                     Env.Notifier.WriteError(ex);
                 }
                 return;
             }
         }
         if (e.Combo == Env.Config.ShowModeCombo)
         {
             e.Capture = true;
             ToggleViewerVisibility();
         }
         else if (!e.Combo.Input.IsMouseInput())
         {
             e.Capture = true;
             LeaveMode();
         }
     }
 }
Exemple #3
0
        private void HandleComposeMode(ComboArgs e)
        {
            if (e.Combo.Input.IsMouseInput())
            {
                return;
            }

            // Capture any non-modifier key. Modifier keys should not be captured as that would prevent the key from modifying the virtual
            // modifier state.
            if (!e.Combo.Input.IsModifierKey())
            {
                e.Capture = true;
            }

            // Check for hit, update hotkeys and input count.
            ModeHotkey hit            = null;
            var        oldModeHotkeys = _modeHotkeys;
            var        oldCount       = _inputCount;

            if (!e.Combo.Input.IsModifierKey())
            {
                var newModeHotkeys = new List <ModeHotkey>();
                foreach (var modeHotkey in _modeHotkeys)
                {
                    if (modeHotkey.Chord.TestPosition(_inputCount, e.Combo))
                    {
                        if (modeHotkey.Chord.Length - 1 == _inputCount)
                        {
                            if (hit == null || modeHotkey.Chord.IsMoreSpecificThan(hit.Chord))
                            {
                                hit = modeHotkey;
                            }
                        }
                        else
                        {
                            newModeHotkeys.Add(modeHotkey);
                        }
                    }
                }
                _inputCount++;
                _modeHotkeys = newModeHotkeys;
            }
            else if (_inputCount == 0)
            {
                hit = _modeHotkeys.FirstOrDefault(z => z.Chord.Length == 1 && z.Chord.TestPosition(0, e.Combo));
            }

            if (hit == null)
            {
                if (e.Combo == Env.Config.ClearModeCombo)
                {
                    ClearInput();
                }
                else if (e.Combo == Env.Config.ShowModeCombo)
                {
                    _modeHotkeys = oldModeHotkeys;
                    _inputCount  = oldCount;
                    ToggleViewerVisibility();
                }
                else if (e.Combo == Env.Config.PrintModeCombo)
                {
                    _modeHotkeys = oldModeHotkeys;
                    _inputCount  = oldCount;
                    Helper.ShowSelectableText(GetDisplayText());
                    LeaveMode();
                }
                else if (Env.Config.ClearModeCombos.Contains(e.Combo))
                {
                    LeaveMode();
                }
            }
            else
            {
                LeaveMode();
                try
                {
                    hit.Action(e.Combo);
                }
                catch (Exception ex) when(!Helper.IsFatalException(ex))
                {
                    Env.Notifier.WriteError(ex);
                }
            }
            _modeViewer.UpdateText(GetDisplayText());
        }