Ejemplo n.º 1
0
        private void OnGlobalHotkeyUp(object sender, GlobalKeyEventArgs e)
        {
            if (PendingGlobalCommand == null)
            {
                return;
            }

            var hotKey = e.HotKey;

            // Execute the pending command only if no modifier key is pressed or it will mess up the keystrokes
            // sent from the command
            if (InputUtil.IsSame(hotKey.Key, hotKey.Modifiers) || !InputUtil.IsModifierKey(hotKey.Key))
            {
                // If hotKey.Key is a modifier key, that modifier key state is still down at the time this event
                // is fired, which may interfere with the keystrokes sent from the automation command below, so we
                // will have to wait a bit more
                TimerUtil.SetTimeOut(() =>
                {
                    // The automation command will probably send some keystrokes (e.g. Ctrl-V to paste text or something)
                    // We dont want the global hook receives and processes those events, thus run this command again
                    _winService.GlobalKeyUp -= OnGlobalHotkeyUp;
                    PendingGlobalCommand.Execute(null);
                    PendingGlobalCommand     = null;
                    _winService.GlobalKeyUp += OnGlobalHotkeyUp;
                }, 1);
            }
        }
Ejemplo n.º 2
0
        private string ReadKeyEvent(KeyEventArgs e)
        {
            // Fetch the actual shortcut key
            var key = (e.Key == Key.System ? e.SystemKey : e.Key);

            if (InputUtil.IsModifierKey(key))
            {
                return("");
            }

            var sb = new StringBuilder();

            if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control))
            {
                sb.Append("Ctrl+");
            }
            if (Keyboard.Modifiers.HasFlag(ModifierKeys.Shift))
            {
                sb.Append("Shift+");
            }
            if (Keyboard.Modifiers.HasFlag(ModifierKeys.Alt))
            {
                sb.Append("Alt+");
            }

            return(sb
                   .Append(key.ToString())
                   .ToString());
        }