如何:列出当前键盘快捷键

使用此过程可创建一个宏,该宏生成的列表列出了集成开发环境 (IDE) 中的所有命令以及根据当前键盘映射方案映射到这些命令的所有快捷键。

IDE 中提供了多种键盘映射方案。 您可以在**“键盘”页上更改键盘映射方案,该页位于“选项”对话框的“环境”**文件夹下。 有关更多信息,请参见如何:使用键盘快捷键

提示

显示的对话框和菜单命令可能会与“帮助”中的描述不同,具体取决于您现用的设置或版本。 若要更改设置,请单击“工具”菜单上的“导入和导出设置”。 有关更多信息,请参见 使用设置

列出当前键盘快捷键映射

  1. 在**“工具”菜单上指向“宏”,再单击“宏 IDE”**。

  2. 在**“项目资源管理器”中双击“MyMacros”**。

  3. 右击**“Module1”,再单击“重命名”**。

  4. 键入 KeyboardShortcuts 作为模块的新名称。

  5. 双击**“KeyboardShortcuts”**可在编辑器中打开该文件。

  6. 将下面的代码粘贴到文件中 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. 在**“文件”菜单上,单击“保存 MyMacros”**。

  8. 切换回 Visual Studio。

  9. 在**“工具”菜单上指向“宏”,再单击“Macro 资源管理器”**。

  10. 展开**“MyMacros”,再展开“KeyboardShortcuts”**。

  11. 右击**“GetAllCommands”,再单击“运行”**。

    该宏生成一个列表,列出 IDE 中所有可能的命令以及这些命令在当前键盘映射方案下所具有的所有键盘快捷键映射。

  12. 在**“视图”菜单上,单击“输出”**。

    命令及其快捷组合键将显示在**“输出”**窗口中。 您可以复制此信息,并将其粘贴到另一个应用程序(如 Microsoft Office Excel)中,用于其他格式设置和打印选项。

请参见

任务

如何:使用键盘快捷键

概念

预定义键盘快捷键

其他资源

Visual Studio 设置