Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to register key binding code on VSIX package installation

I'd like to add keyboard shortcut to Visual Studio package only once, during its installation. Basically I know how to do it from the package code, for example:

var dte = GetGlobalService(typeof(DTE)) as DTE2;
if (dte != null)
{                
    dte.Commands.Item("Tools.Something").Bindings = "Global::Ctrl+T, Ctrl+S";
}

The problem is, I'd like to invoke this code only once (I don't want to execute this code in package class constructor, because it will execute each time the package will be used first time after VS restart).

How to do it ?

like image 778
jwaliszko Avatar asked Dec 03 '25 18:12

jwaliszko


1 Answers

There is another way I wasn't aware last time. All what need to be done is adding key binding in the *.vsct file. This will register your key shortcut and bind it to the selected command.

<KeyBindings>
    <KeyBinding guid="guidSomehingCmdSet" id="cmdidSomehing" editor="guidVSStd97" mod1="Control" mod2="Control" key1="T" key2="S" />    
</KeyBindings>
like image 161
jwaliszko Avatar answered Dec 06 '25 11:12

jwaliszko