2016-12-15 8 views
0

こんにちはVS 2015はバグがあり、時々私のショートカットのいくつかを復元しなければなりませんでした。 F.e. ctrl +; LineEndと他のもののために。マクロを使って、これをプログラム的にやる方法がありますか?Visual Studioのキーボードショートカットをプログラム的に作成する方法

解決済み。コマンド対に割り当てられたすべてのキーボードショートカットは、(それがVSIX develor避けることができます)はっきりしていないスクリプトが更新されます

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; 
    } 
} 
+0

インストールに問題がある場合は、VSがバグであると想定せずに修復する必要があります。問題は残り、おそらく悪化するでしょう。ショートカットについては、単純に*リセットしないのはなぜですか?または、[ツール]> [インポートとエクスポートの設定]からエクスポート/インポートしますか? BTW LineEndはEndキーに過ぎません。 –

+0

[Visual Studioでのキーボードショートカットの特定とカスタマイズ](https://msdn.microsoft.com/en-us/library/5zwses53.aspx)をチェックしてください。キーボードショートカットを含む設定をエクスポートする方法を示します。 –

+0

devenv.exe/ResetSettingsを実行して、IDE全体のデフォルト設定に戻すことができます。他のカスタマイズを失っても構わない場合は、それは可能でしょうか? –

答えて

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マニュアルを参照してください詳細については。

+0

ありがとうございます。素晴らしいツール、それはおそらく少しのハードコアで私の問題を解決:)警告このscritp vsコマンドからすべての定義されたキーボードショートカットを削除します。 – Igor

関連する問題