1 out of 2 rated this helpful - Rate this topic

How to: List Current Keyboard Shortcuts

Use this procedure to create a macro that generates a list of all the commands in the integrated development environment (IDE) and any shortcut keys mapped to those commands according to the current keyboard mapping scheme.

Several keyboard mapping schemes are available in the IDE. You can change keyboard mapping schemes on the Keyboard page, under the Environment folder of the Options dialog box. For more information, see How to: Work with Keyboard Shortcuts.

NoteNote

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, click Import and Export Settings on the Tools menu. For more information, see Working with Settings.

To list current keyboard shortcut mappings

  1. On the Tools menu, point to Macros, and then click Macros IDE.

  2. In Project Explorer, double-click MyMacros.

  3. Right-click Module1 and then click Rename.

  4. Type KeyboardShortcuts as the new name for the module.

  5. Double-click KeyboardShortcuts to open the file in the editor.

  6. Paste the following code in the file after Public Module KeyboardShortcuts:

    Sub GetAllCommands()
    
        Dim cmd As Command
        Dim ow As OutputWindow = DTE.Windows.Item(Constants.vsWindowKindOutput).Object
        Dim owp As OutputWindowPane
        Dim exists As Boolean
        Dim i As Integer
        Dim sArray() As String
    
        sArray = New String() {}
        i = 1
        exists = False
    
        For Each owp In ow.OutputWindowPanes
            If owp.Name = "Macro Output" Then
                exists = True
                Exit For
            End If
            i = i + 1
        Next
    
        If exists Then
            owp = ow.OutputWindowPanes.Item(i)
        Else
            owp = ow.OutputWindowPanes.Add("Macro Output")
        End If
    
        owp.Clear()
    
        ' Output 1 line per command
        For Each cmd In DTE.Commands
            Dim binding As Object
            Dim shortcuts As String
            shortcuts = ""
    
            For Each binding In cmd.Bindings
                Dim b As String
                b = binding
                If Not shortcuts = "" Then
                    shortcuts += "--OR-- "
                End If
                shortcuts = shortcuts + b + " "
            Next
    
            shortcuts = shortcuts.Trim()
    
            If Not cmd.Name.Trim().Equals("") And Not shortcuts.Equals("") Then
                sArray.Resize(sArray, sArray.Length + 1)
                sArray(sArray.Length - 1) = cmd.Name + vbTab + shortcuts
            End If
        Next
    
        Array.Sort(sArray)
        owp.OutputString(String.Join(vbCrLf, sArray))
    
    End Sub
    
  7. On the File menu, click Save MyMacros.

  8. Switch back to Visual Studio.

  9. On the Tools menu, point to Macros and then click Macro Explorer.

  10. Expand MyMacros and then expand KeyboardShortcuts.

  11. Right-click GetAllCommands and then click Run.

    The macro generates a list of all possible commands in the IDE and any keyboard shortcut mappings these commands have in the current keyboard mapping scheme.

  12. On the View menu, click Output.

    Commands and their shortcut key combinations appear in the Output window. You can copy this information and paste it into another application, such as Microsoft Office Excel, for additional formatting and printing options.

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Too much output for output window
How about the following as an alternative, which puts the contents into a new text document - more usable form.

    Sub GetAllCommands2()

 

        Dim cmd As Command

        Dim sArray() As String

        Dim doc As Document

        Dim textDoc As TextDocument

        Dim new_window As EnvDTE.Window

        Dim binding As Object

        Dim shortcuts As String

        Dim b As String

 

        new_window = DTE.ItemOperations.NewFile("General\Text File")

        doc = new_window.Document

        textDoc = CType(doc.Object("TextDocument"), TextDocument)

        textDoc.StartPoint.CreateEditPoint() ' Creates an "edit point" at the beginning of the document

 

        sArray = New String() {}

 

        ' Output 1 line per command

        For Each cmd In DTE.Commands

            If cmd.Name.Trim().Equals("") Then Continue For

            

            ' Create a string of all the keybindings for the given command

            shortcuts = ""

            For Each binding In cmd.Bindings

                b = binding

                If Not shortcuts = "" Then

                    shortcuts += "--OR-- "

                End If

                shortcuts = shortcuts + b + " "

            Next

            shortcuts = shortcuts.Trim()

            If shortcuts.Equals("") Then Continue For

            'textDoc.Selection.Insert("_" + cmd.Name + vbCrLf)

            'textDoc.Selection.Insert(" > " + shortcuts + vbCrLf)

            sArray.Resize(sArray, sArray.Length + 1)

            sArray(sArray.Length - 1) = cmd.Name + vbTab + shortcuts

        Next

 

        Array.Sort(sArray)

        textDoc.Selection.Insert(String.Join(vbCrLf, sArray)) ' Inserts text there. 

 

    End Sub