Bindings Property Parameter Format
The Bindings property has a specific parameter format which you must follow, or you will receive an error. The parameters required are following.
Bindings Property Parameters
The parameter format is: Scope::ModifierKeys1+Key1,ModifierKeys2+Key2.
The following shows two keybindings that apply to one command in the Global scope. These key bindings are Ctrl-Shift-D followed by the O key and Ctrl-Shift-D followed by the F key: Global::Ctrl+Shift+D,O,Ctrl+Shift+D,F.
In this case, the modifier keys and key values are:
Parameter |
Value |
---|---|
Scope |
Global |
ModifierKeys1 |
Ctrl+Shift+D |
Key1 |
O |
ModifierKeys2 |
Ctrl+Shift+D |
Key2 |
F |
If you are using Visual Studio with the default settings, then the assigned shortcut key for the File.NewFile command is Global::Ctrl+N. This means that pressing and holding CTRL while pressing N displays the New File dialog box. The Global keyword means that the command works in all areas of Visual Studio.
Scope
The Scope parameter indicates the context in which the shortcut key works. The Global keyword defines that it works anywhere in Visual Studio, while a specific scope defines that it works only in that scope. Global is the most often-used scope. The available values for Scope depend on the package.
For example, CTRL+B makes the selected text bold when in the HTML editor, but the same key combination displays the Debugger Breakpoints dialog box if the editor is inactive. If you were to apply a Global scope to this shortcut key combination, then CTRL+B would work (or attempt to work) the same everywhere in Visual Studio, rather than only in the HTML editor.
Regardless of the scope you use, you must follow it with two colons (::) before specifying the other parameters.
Modifier Keys1
Modifier keys are system keys that you press while pressing another key. The available modifier keys are CTRL, SHIFT, and ALT. You can combine more than one modifier key by separating them with a + sign. For example: CTRL+ALT+X or SHIFT+ALT+Y. You can also specify multiple letters, such as CTRL+ALT+Y, N, meaning you press CTRL+ALT+Y and then the N key.
Key1
A key is any key on a standard 102-key keyboard. Excluded keys on newer keyboards are: the Windows key, multimedia keys (such as favorites, volume, stop, etc.), and the Fn key on some portable computers. Keys other than the standard letter and number keys are known as virtual keys. The following table lists all virtual keys that the Bindings property accepts. Any virtual key not in this list is ignored.
BACK |
DELETE |
INSERT |
SPACE |
F1 |
F2 |
F3 |
F4 |
F5 |
F6 |
F7 |
F8 |
F9 |
F10 |
F11 |
F12 |
F13 |
F14 |
F15 |
F16 |
F17 |
F18 |
F19 |
F20 |
F21 |
F22 |
F23 |
F24 |
RETURN |
CANCEL |
UP |
DOWN |
LEFT |
RIGHT |
TAB |
HOME |
END |
PRIOR |
NEXT |
ESCAPE |
DECIMAL |
MULTIPLY |
SUBTRACT |
ADD |
DIVIDE |
NUMPAD0 |
NUMPAD1 |
NUMPAD2 |
NUMPAD3 |
NUMPAD4 |
NUMPAD5 |
NUMPAD6 |
NUMPAD7 |
NUMPAD8 |
NUMPAD9 |
Modifier Keys2 and Key2
These optional additional keys let you expand your command groups and avoid shortcut key collisions. For example, you could assign CTRL+SHIFT+D, O to open a file in the file editor, and you could assign CTRL+SHIFT+D, S to save the file. Also, this lets you group similar commands under the same keyboard shortcut for ease of use and memorization. It also avoids expending all the shorter available shortcut keys that are frequently used by other commands.
See Also
Tasks
How to: Bind a Command to a Single Shortcut Key
How to: Bind a Command To Multiple Combinations of Shortcut Keys
How to: Preserve Existing Command Key Bindings