This documentation is archived and is not being maintained.

How to: View Existing Key Bindings

The Bindings property enables you to view or change the key bindings associated with a specified command. Reading this property retrieves the command's current bindings as an array of objects. Each object contains a string that describes the binding.

Setting a value to the Bindings property assigns one or more new key bindings to the specified command. For more information, see How to: Bind a Command to a Single Shortcut Key and How to: Bind a Command To Multiple Combinations of Shortcut Keys.

NoteNote:

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. These procedures were developed with the General Development Settings active. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

Viewing existing key bindings

  1. Use the Visual Studio Add-In Wizard to create a new add-in. Name the project and click OK to start the wizard.

    For more information about using the Visual Studio Add-In Wizard, see How to: Create an Add-In.

  2. On the Select a Programming Language page, select either Create an Add-in using Visual C# to run the Visual C# example below, or Create an Add-in Using Visual Basic to run the Visual Basic example.

  3. Paste the example function below to the Connect class in the Visual Studio Add-In Wizard generated code.

  4. Call the function from the OnConnection method as described in How to: Compile and Run the Automation Object Model Code Examples.

  5. To run the Add-in, click Add-in Manager on the Tools menu, select the add-in you created, and click OK.

    A list of all shortcut keys bound to the File.NewFile command displays.

The following example illustrates the use of Bindings by displaying all shortcut keys bound to the File.NewFile command.

// Add-in code.
public void OnConnection(object application,
 Extensibility.ext_ConnectMode connectMode, object addInInst, ref
 System.Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;

    //Pass the applicationObject member variable to the code example.
    ListKeyBindings((DTE2)_applicationObject);
}
public void ListKeyBindings(DTE2 dte)
{
    object[] bindings;
    string msg = string.Empty;
    // Populate the collection with all of the bindings associated
    // with the command File.NewFile.
    // Bindings() is an array of key binding string names.
    bindings = (object[])dte.Commands.Item("File.NewFile", 0).Bindings;
    foreach (object b in bindings)
    {
        msg += ((string)b) + "\n";
    }
    System.Windows.Forms.MessageBox.Show(msg);
}
Show: