How to make a shortcut to run the VSIX method?

see this question.

The initial question was resolved and I have a method in my extension. I want that when the user installs the extension, the keyboard shortcut should be installed and should start the method when clicked.

How to do it?

+3
source share
1 answer

You can add shortcuts to the .vsct file. This file is created automatically in the wizard when creating a new extension and says that it will have a menu command. To add it manually:

  • Create MyCommands.vsct
  • Set file properties for VSCTCompile
  • Unload the project, right-click and edit the project:

:

<VSCTCompile Include="MyCommands.vsct">
    <ResourceName>Menus.ctmenu</ResourceName>
    <SubType>Designer</SubType>
</VSCTCompile>
  • , :

:

[ProvideMenuResource("Menus.ctmenu",1)]
public sealed class MyPackage : Package
  • :

:

<KeyBindings>
   <KeyBinding guid="yourCmdSet" id="cmdAwesome"
    editor="guidVSStd97"
    key1="VK_F7" mod1="Control Alt"
    key2="VK_F1">
   </KeyBinding>
</KeyBindings>
  • Package.Initialize:

:

// Add our command handlers for menu/shortcut (commands must exist in the .vsct file)
OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
if (null != mcs)
{
    //// Create the command for the menu item.
    var menuCommandID = new CommandID(GuidList.yourCmdSet,(int)PkgCmdIDList.cmdAwesome);
    var menuItem = new MenuCommand((sender, evt) =>
    {
        // Do stuff
    }
}

:

+4

All Articles