please see this question.
The initial question was solved, and I have a method in my extension. I want that when the user installs the extension, a keyboard-shortcut should be installed as well, and should run the method when pressed.
How do I do this?
You can add shortcuts to the .vsct file. This file is created automatically in the wizard when you generate a new extension and say it will have a menu command. To add it manually:
<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>
// 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
}
}
More resources:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With