visual-studiovisual-studio-extensionsvisual-studio-sdk

VS SDK: Command should not be visible in menu, but only accessible via keyboard shortcut


I am developing a very small extension right now. I don't want to add my newly added commands to the menu as buttons. Instead, I would like to execute these commands via keyboard shortcut only. I have successfully added the keyboard shortcuts to the commands by adding the Keybindings section to the *Package.vsct.

<Buttons>
      <Button guid="guidJumpToEndOfWordPackageCmdSet" id="JumpToEndOfWordId" priority="0x0100" type="Button">
        <Parent guid="guidJumpToEndOfWordPackageCmdSet" id="MyMenuGroup" />
        <Strings>
          <ButtonText>WordNextEnd</ButtonText>
        </Strings>
      </Button>
</Buttons>
<KeyBindings>
    <KeyBinding guid="guidJumpToEndOfWordPackageCmdSet" id="JumpToEndOfWordId"      editor="guidVSStd97" key1="VK_RIGHT" mod1="Control" />
</KeyBindings>

However, as soon as I remove the Buttons section or hide the button, the keybinding also doesn't work anymore. Any suggestions on how to fix this?


Solution

  • I have found the answer. Just add this to the button section:

    <CommandFlag>CommandWellOnly</CommandFlag>
    

    This way, the command is just executable via command line or keyboard shortcut.