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; }
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(); }