How to: View Existing Key Bindings

Visual Studio add-ins are deprecated in Visual Studio 2013. You should upgrade your add-ins to VSPackage extensions. For more information about upgrading, see FAQ: Converting Add-ins to VSPackage Extensions.

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 Keyboard Shortcuts.

Note Note

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 Customizing Development Settings in Visual Studio.

Viewing existing key bindings

  1. Create an add-in.

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

  2. Add a reference to System.Windows.Forms, and add this namespace to the using (or Imports) statements for the Connect class.

  3. Paste the function below into the Connect class in the code.

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

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

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.
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";