次の方法で共有


Command.Bindings Property

Definition

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

public:
 property System::Object ^ Bindings { System::Object ^ get(); void set(System::Object ^ value); };
public:
 property Platform::Object ^ Bindings { Platform::Object ^ get(); void set(Platform::Object ^ value); };
[System.Runtime.InteropServices.DispId(9)]
public object Bindings { [System.Runtime.InteropServices.DispId(9)] get; [System.Runtime.InteropServices.DispId(9)] set; }
[<System.Runtime.InteropServices.DispId(9)>]
[<get: System.Runtime.InteropServices.DispId(9)>]
[<set: System.Runtime.InteropServices.DispId(9)>]
member this.Bindings : obj with get, set
Public Property Bindings As Object

Property Value

A SafeArray of objects.

Attributes

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  

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.

Applies to