Compartir a través de


Command.Bindings Property

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

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

Syntax

'Declaration
Property Bindings As Object
Object Bindings { get; set; }
property Object^ Bindings {
    Object^ get ();
    void set (Object^ value);
}
abstract Bindings : Object with get, set
function get Bindings () : Object 
function set Bindings (value : Object)

Property Value

Type: System.Object
A SafeArray of objects.

Remarks

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+", which must be specified in English. 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.

Note

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.

Examples

Sub BindingsExample()
    Dim cmds As Commands
    Dim cmd As Command
    Dim props As EnvDTE.Properties = DTE.Properties("Environment", _
    "Keyboard")
    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 _
    Data\Microsoft\VisualStudio\8.0\MyNewKbdScheme.vsk"
    MsgBox("PROP NAME: " & prop.Name & "   VALUE: " & prop.Value)
    cmd.Bindings = "Global::f2"
End Sub

.NET Framework Security

See Also

Reference

Command Interface

EnvDTE Namespace

Other Resources

Binding Add-In Commands to Keys