コード例 #1
0
        private void KeyCapturingTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            Key key = GetKey(e);

            // Certain keys are not captured by design.  Check for those here and exit early.
            if (!ShouldCapture(key))
            {
                return;
            }

            e.Handled = true;

            ModifierKeys modifiers = Keyboard.Modifiers;

            if (e.Key == Key.Back && modifiers == ModifierKeys.None)
            {
                if (BindingSequences.Count > 0)
                {
                    BindingSequences.RemoveAt(BindingSequences.Count - 1);
                }
            }
            else
            {
                if (BindingSequences.Count == 2)
                {
                    BindingSequences.Clear();
                }

                string keyName = key.ToString();
                BindingSequences.Add(new BindingSequence(modifiers, keyName));
            }

            base.Text       = string.Join(", ", BindingSequences);
            base.CaretIndex = base.Text.Length;
        }
コード例 #2
0
        private void KeyCapturingTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            Key key = GetKey(e);

            // Certain keys are not captured by design.  Check for those here and exit early.
            if (!ShouldCapture(key))
            {
                return;
            }

            // Allow user to input Tab only when there are no keys in the sequence yet; otherwise, Tab
            // moves to the next control.
            if (BindingSequences.Count > 0 && (key == Key.Tab))
            {
                return;
            }

            e.Handled = true;

            if (BindingSequences.Count == 2)
            {
                BindingSequences.Clear();
            }

            ModifierKeys modifiers = Keyboard.Modifiers;
            string       keyName   = key.ToString();

            BindingSequences.Add(new BindingSequence(modifiers, keyName));

            base.Text       = string.Join(", ", BindingSequences);
            base.CaretIndex = base.Text.Length;
        }
コード例 #3
0
        private void KeyCapturingTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            Key key = GetKey(e);

            // Certain keys are not captured by design.  Check for those here and exit early.
            if (!ShouldCapture(key))
            {
                return;
            }

            e.Handled = true;

            ModifierKeys modifiers = Keyboard.Modifiers;

            if (e.Key == Key.Back && modifiers == ModifierKeys.None)
            {
                if (BindingSequences.Count > 0)
                {
                    BindingSequences.RemoveAt(BindingSequences.Count - 1);
                }
            }
            else
            {
                if (BindingSequences.Count == 2)
                {
                    BindingSequences.Clear();
                }

                string keyName = key.ToString();
                BindingSequences.Add(new BindingSequence(modifiers, keyName));
            }

            // Print the text to the input box
            UpdateShortcutKeysDisplay();
        }