VS 2013 SDK: How to keybind hotkey only for Code Window Editor?

前端 未结 2 1791
说谎
说谎 2021-01-21 08:41

In C# or else VB.Net, using a Visual Studio Package, I would like to assign a custom keyboard shortcut to a CommandBarBu

2条回答
  •  [愿得一人]
    2021-01-21 09:45

    In Visual Studio, keyboard shortcuts are associated to commands, not directly to CommandBarButtons. Technically they are called Keyboard Bindings and are declared in the .vsct file where you declare commands. See KeyBindings element

    Edited: You have to use:

      
    

      
    
      
    
      
    

    ...

    where guidSourceCodeTextEditor can be any name that you define in the section whose value you must get from HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0Exp_Config\Editors. Once you run the package, if you go to Tools >Options window, Environment > Keyboard section, type the name of your command in Show Commands Containing, and you should see the shortcut in the list with the editor between parenthesis, as if you have selected it from the "Use new shortcut in" list. Which yields us to the question if the guids are the same for each Visual Studio version. AFAIK, this is not guaranteed (nothing prevents Microsoft changing guids in a new version) but likely they are the same. I cannot verify right now because the computer that I am using only has VS 2013.

提交回复
热议问题