如何为VS操作创建visual studio键盘快捷键?

时间:2016-12-15 12:33:27

标签: visual-studio visual-studio-2015

你好VS 2015是错误的,我不得不不时恢复我的一些快捷方式。 F.E. ctrl +;对于LineEnd和其他一些人。有没有办法通过宏等方式进行程序化?

解决。有一个更新的脚本,不清除分配给vs命令的所有键盘快捷键(它有助于避免develor VSIX):

using System;
using EnvDTE;
using EnvDTE80;

public class C : VisualCommanderExt.ICommand
{
    public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) 
    {
        string commandName = "Edit.LineEnd";
        string shortcut = "Text Editor::ctrl+;";

        EnvDTE.Command cmd= DTE.Commands.Item(commandName, 0);

        // Retrieve the current bindings for the command.
        Object[] bindings = ((System.Object[])(cmd.Bindings)); 
            // Get the number of bindings for the command.
            int bindingNumber = bindings.Length; 
            // Add two more elements to the array to accomodate two
            // new commands.
            // Create temp variable for copying values. 
            // Arrays are zero-based in C#.
            object[] temp = new object[bindingNumber + 1]; 
            System.Array.Copy( bindings, temp, Math.Min(bindings.Length, temp.Length)); 
        bindings = temp;

            // Add the new bindings to the existing ones in the array.
            bindings[bindingNumber] = shortcut; 

        cmd.Bindings = bindings;
    }
}

1 个答案:

答案 0 :(得分:1)

您可以在我的Visual Commander扩展程序中使用以下命令:

public class C : VisualCommanderExt.ICommand
{
    public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) 
    {
        this.DTE = DTE;
        SetShortcut("Edit.LineEnd", "Text Editor::ctrl+;");
    }

    private void SetShortcut(string commandName, string shortcut)
    {
        EnvDTE.Command command = DTE.Commands.Item(commandName, 0);
        command.Bindings = shortcut;
    }

    EnvDTE80.DTE2 DTE;
}

有关详细信息,请参阅Command.Bindings文档。