コード例 #1
0
            private bool findCollision(Utils.KeyCombination shortcut)
            {
                string collision;

                if (!knownShortcuts.TryGetValue(shortcut, out collision) &&
                    this.allSettableShortcuts != null)
                {
                    var collisionRecorder = this.allSettableShortcuts
                                            .FirstOrDefault(r => r != this && r.Shortcut == shortcut);

                    if (collisionRecorder != null)
                    {
                        collision = collisionRecorder.ShortcutName;
                    }
                }

                if (collision == null)
                {
                    return(false);
                }

                this.errorText.Text = string.Format(
                    "{0} already taken by: {1}",
                    keyEventToString(shortcut), collision
                    );

                return(true);
            }
コード例 #2
0
        private static string keyEventToString(Utils.KeyCombination shortcut)
        {
            var modifiers = shortcut.Modifiers;

            var res = "";

            if (modifiers.HasFlag(TogglDesktop.ModifierKeys.Win))
            {
                res += "Win + ";
            }
            if (modifiers.HasFlag(TogglDesktop.ModifierKeys.Control))
            {
                res += "Ctrl + ";
            }
            if (modifiers.HasFlag(TogglDesktop.ModifierKeys.Shift))
            {
                res += "Shift + ";
            }
            if (modifiers.HasFlag(TogglDesktop.ModifierKeys.Alt))
            {
                res += "Alt + ";
            }
            res += shortcut.KeyCode;
            return(res);
        }
コード例 #3
0
            private void setShortcut(Utils.KeyCombination shortcut)
            {
                this.Shortcut   = shortcut;
                this.HasChanged = true;

                this.button.Content = keyEventToString(shortcut);
                this.errorText.Text = "";
            }
コード例 #4
0
            private void onKeyUp(object sender, KeyEventArgs e)
            {
                if (!this.recording)
                {
                    return;
                }

                var key = (e.Key == Key.System ? e.SystemKey : e.Key);

                // ignore modifier key releases
                if (this.checkModifiers(key))
                {
                    return;
                }

                var mods = this.activatedModifiers;

                if ((mods & requiredModifiersUnion) == ModifierKeys.None)
                {
                    if (key == Key.Enter || key == Key.Space)
                    {
                        // this happens when user starts recoding with keyboard
                        return;
                    }

                    this.errorText.Text = "Shortcut must contain Alt, Ctrl, or Windows key.";

                    this.cancelRecording();
                    return;
                }

                this.cancelRecording();

                if (key == Key.None)
                {
                    this.errorText.Text = "Something went wrong. Please try again.";
                    return;
                }

                e.Handled = true;

                var keyString = key.ToString();

                var shortcut = new Utils.KeyCombination(mods, keyString);

                if (this.findCollision(shortcut))
                {
                    return;
                }

                this.setShortcut(shortcut);
            }
コード例 #5
0
            private void onKeyUp(object sender, KeyEventArgs e)
            {
                if (!this.recording)
                    return;

                var key = (e.Key == Key.System ? e.SystemKey : e.Key);

                // ignore modifier key releases
                if (this.checkModifiers(key))
                    return;

                var mods = this.activatedModifiers;

                if ((mods & requiredModifiersUnion) == ModifierKeys.None)
                {
                    if (key == Key.Enter || key == Key.Space)
                    {
                        // this happens when user starts recoding with keyboard
                        return;
                    }

                    this.errorText.Text = "Shortcut must contain Alt, Ctrl, or Windows key.";

                    this.cancelRecording();
                    return;
                }

                this.cancelRecording();

                if (key == Key.None)
                {
                    this.errorText.Text = "Something went wrong. Please try again.";
                    return;
                }

                e.Handled = true;
                
                var keyString = key.ToString();

                var shortcut = new Utils.KeyCombination(mods, keyString);

                if (this.findCollision(shortcut))
                    return;

                this.setShortcut(shortcut);
            }