none
Add Keyboard Shortcut to XML Button RRS feed

  • Question

  • Hi All,

    Struggling with figuring out how to specify a keyboard shortcut value for a custom contextMenu button.  Figured out how to customize the context menu itself just fine, but can't figure out how to assign a keyboard shortcut to my new buttons in the contextMenu.

    VSTO/Office 2010/Win7/etc..

    XML segment is:

    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
      ....

    <contextMenus>
        <contextMenu idMso="ContextMenuRevision">
          <button id="AAbtn" label="MyLabel" getImage="getImage" insertBeforeMso="ReviewTrackChanges"
                   onAction="AccOnbtn" getEnabled="enableCM"
                   />
        </contextMenu>
    </contextMenus>
    </customUI>

    So how do I specify a keyboard shortcut to "MyLabel", say I want it to be "M"?

    Thanks, billwa992

     

    Saturday, December 10, 2011 12:52 AM

Answers

  • Hi Bill

    The shortcut menu is displayed using Shift + F10. After that, the user can press a designated key, represented by the underlined character in the caption (label attribute).

    As customary in Windows, the designated character in the caption is indicated by an ampersand (&). In order to include this in your Ribbon XML, you have to use the HTML way of representing the ampersand: 

    label="&amp;xyz"

    The caption then looks like this: xyz

    So the keyboard shortcut would be: Shift+F10, x

    Other than that, there's no way to link any command that's not VBA to a keyboard combination unless you resort to "keyboard hooks" in the Windows API.


    Cindy Meister, VSTO/Word MVP

      label

    ="&amp;xyz"

    Saturday, December 10, 2011 9:43 AM
    Moderator

All replies

  • Hi Bill

    The shortcut menu is displayed using Shift + F10. After that, the user can press a designated key, represented by the underlined character in the caption (label attribute).

    As customary in Windows, the designated character in the caption is indicated by an ampersand (&). In order to include this in your Ribbon XML, you have to use the HTML way of representing the ampersand: 

    label="&amp;xyz"

    The caption then looks like this: xyz

    So the keyboard shortcut would be: Shift+F10, x

    Other than that, there's no way to link any command that's not VBA to a keyboard combination unless you resort to "keyboard hooks" in the Windows API.


    Cindy Meister, VSTO/Word MVP

      label

    ="&amp;xyz"

    Saturday, December 10, 2011 9:43 AM
    Moderator
  • Cindy,

    Great - it was the "&amp;" syntax that I was unable to find anywhere.  Many times, the toughest part of the problem is figuring out how to specify the question in search to obtain the source for the answer.  For instance, I searched on all kinds of combinations of shortcut, keyboard shortcut, context menu, shortcut XML, etc..  looking for how to specify the syntax for my UI XML file and obviously did not run across this syntax.  I had tried just the "&" but of course, XML interpretted that as simply a variable name, I believe.  So maybe it is simply my lack of XML knowledge/experience. 

    Hopefully this post will help others as well.

    Thanks for the assist.

    billwa992

    Saturday, December 10, 2011 9:19 PM
  • Hi Bill

    I picked it up on my side from a post by Bessie Zhao, in the VSTO forum :-)


    Cindy Meister, VSTO/Word MVP
    Sunday, December 11, 2011 6:32 AM
    Moderator