How to register key binding code on VSIX package installation

不想你离开。 提交于 2019-12-05 20:11:39

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>

First of all, if you plan to publicly distribute the extension then you should probably remove the binding due to an extremely high likelihood it will interfere with existing bindings of some of your users.

Second, provide the command and binding as part of a Visual Studio Command Table, not via the automation interfaces. The commands are registered using the [ProvideMenuResourceAttribute] attribute which does not require any code to execute when the package is installed.

  • Check the a registry key every time in package init() function
  • if key not present create registry key and execute your code
  • If key found, don't execute your code

For example: 1. Check "Test" key in your desired location 2. If "Test" key not present create that key in registry and execute your code 3. If "Test" key found, don't execute your code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!