This documentation is archived and is not being maintained.

Command.Bindings Property

Sets or gets the list of keystrokes used to invoke the command.

Namespace: EnvDTE
Assembly: EnvDTE (in envdte.dll)

Object Bindings { get; set; }
/** @property */
Object get_Bindings ()

/** @property */
void set_Bindings (Object pVar)

function get Bindings () : Object

function set Bindings (pVar : Object)

Property Value

A SafeArray of objects.

Bindings sets or returns a SafeArray of objects containing strings that describe all of the key bindings for the specified command. You add bindings to the command by adding them to the SafeArray and then setting it back afterwards. You remove bindings from the command by removing them from the SafeArray and then setting it back afterwards.

The syntax of each string is either one of the following (where "modifiers+" is optional):

  • "scopename::modifiers+key"

  • "scopename::modifiers+key, modifiers+key"

Modifiers are "ctrl+", "alt+", and "shift+". They can appear in any order. The first modifier or key specifier immediately follows the double colons ("::"). There is one space after any comma separator in a key sequence.

Everything is reported by using mixed case, such as "Ctrl+Space", but you can use any case combination when adding new bindings.

Spaces are handled as literals in the binding string. There are no escape sequences for space and tab characters, and so forth. Some examples of binding settings are:

  • "Text Editor::ctrl+r, ctrl+r"

  • "Global::ctrl+o"

  • "Global::f2"

Bindings returns Nothing for commands that cannot have bindings, that is, they do not show up in the Tools Options keyboard bindings property page. If you attempt to set this property for such a command, an error returns.


You cannot programmatically change the settings for the default keyboard mapping scheme. To change the settings, save a copy of the default keyboard mapping scheme in the Keyboard node in the Options dialog box. You can then change the settings in that mapping scheme.

' Macro code.
Sub BindingsExample()
    Dim cmds As Commands
    Dim cmd As Command
    Dim props As EnvDTE.Properties = DTE.Properties("Environment", _
    Dim prop As EnvDTE.Property

    ' Set references to the Commands collection and the File.NewFile 
    ' command.
    cmds = DTE.Commands
    cmd = cmds.Item("File.NewFile")

    ' Assigns the command (File.NewFile) globally to the F2 key.
    ' Because you cannot programmatically change the default keyboard 
    ' mapping scheme settings, you must first make a copy of the 
    ' Default Settings for the Keyboard Mapping Scheme.
    prop = props.Item("Scheme")
    ' Sets the Scheme property value to a new keyboard scheme.
    ' This saves the old keyboard mapping scheme and allows you 
    ' to add new key mappings.
    MsgBox("PROP NAME: " & prop.Name & "   VALUE: " & prop.Value)
    prop.Value = "C:\Documents and Settings\johndoe\Application _
    MsgBox("PROP NAME: " & prop.Name & "   VALUE: " & prop.Value)
    cmd.Bindings = "Global::f2"
End Sub