
Now I want a shortcut key to do my own thing. For example, "Ctrl + -", but the shortcut key is bound to the control itself by default. How can I set it to work with my own behavior?
Now I want a shortcut key to do my own thing. For example, "Ctrl + -", but the shortcut key is bound to the control itself by default. How can I set it to work with my own behavior?
If you want total control over input bindings, you can override the "SyntaxEditor.ResetInputBindings" method and set the bindings you want. If you never call the base method, none of the default input bindings will be defined.
If you just want to remove a single input binding, you can find that key combination in the input bindings collection and remove it. Note that some commands, like the ZoomOut command, can have multiple input bindings since the "minus" key is also the "subtract" key on the number pad.
You can use the "Edit Actions" QuickStart in the Sample Browser to view the first input binding for each command.
You could use something like the following code to clear the "Ctrl + -" binding:
...
RemoveInputBinding(Key.OemMinus, ModifierKeys.Control);
RemoveInputBinding(Key.Subtract, ModifierKeys.Control);
...
private void RemoveInputBinding(Key key, ModifierKeys modifiers) {
foreach (InputBinding binding in editor.InputBindings) {
KeyBinding keyBinding = binding as KeyBinding;
if (keyBinding != null) {
if (keyBinding.Key == key && keyBinding.Modifiers == modifiers) {
editor.InputBindings.Remove(keyBinding);
break;
}
}
}
}
Please log in to a validated account to post comments.