Programmatically click splitbutton and ribbonmenu

Add-in Express™ Support Service
That's what is more important than anything else

Programmatically click splitbutton and ribbonmenu
 
nwein




Posts: 577
Joined: 2011-03-28
My ribbon structure has a split button, underneath it a ribbon menu and underneath that, another ribbon menu.
I'm trying to programmatically click the last ribbon menu so that it will be visible in the Office host via a shortcut (i.e. not the action of the button, but displaying the list of buttons found under the last ribbon menu so that a user can select which button to press).
I can't seem to get it to work. In my shortcut handler (which is being triggered) i'm trying to use SendKeys with the the KeyTip chain needed to achieve my goal, but:
a) the KeyTip I assign to my ribbon is not what i'm assigning it (e.g. I assign it the combination "ABC" but when I open the office host and click Alt, I see that the shortcut is not ABC but rather an arbitrary Y2 (Y1 is taken by another add-in). The keytips within my ribbon are fine though.
b) even if I change my shortcut code to send keys Y2 etc. it doesn't work.

My question(s) are: why doesn't the key tip works for the ribbon itself?
What am I doing wrong?
Can this be achieved in another way (sendkeys is not ideal, but I can't seem to find another way to expose the menu button via a shortcut)?

These are my code attempts (executed each one by itself). (My ShortcutText is Ctrl_Shift_SPACE):

private void _keyboardShortcut_Action(object sender)
{
    SendKeys.Send("%ABC%TT%YU"); // first attempt
    SendKeys.Send("%Y2"); // second attempt, just to get to my ribbon, ribbon.Activate doesn't expose the rest or my ribbon shortcuts
    SendKeys.Send("%(Y2)"); // third attempt
    SendKeys.Send("%Y2(ENTER)"); // fourth attempt
}
Posted 06 Apr, 2020 09:17:54 Top
Andrei Smolin


Add-in Express team


Posts: 18791
Joined: 2006-05-11
Hello Nir,

I assume renaming A with Y2 is a built-in Ribbon behavior: it looks like they do this to avoid using the same key twice/thrice.

I've never used SendKeys. I've tested this and yes, this works to a certain extent. You can see this yourself: press {Alt} and then use keys to open the lowest menu. After I expand the splitbutton menu in this way, no keytips are available any longer in my Excel 365.

I suggest that you show a pane and use standard .NET controls on it.


Andrei Smolin
Add-in Express Team Leader
Posted 06 Apr, 2020 10:42:58 Top
nwein




Posts: 577
Joined: 2011-03-28
Thanks for looking into it. Yeah, I guess I'll find a different approach.
Perhaps it makes sense for you guys to not expose the KeyTip for a ribbon control if that is not being respected (although I don't know, perhaps it is being respected in previous versions of Office...)
Posted 06 Apr, 2020 10:53:36 Top
Andrei Smolin


Add-in Express team


Posts: 18791
Joined: 2006-05-11
Hello Nir,

The Office Ribbon schema requires us to have a KeyTip on every Ribbon control.


Andrei Smolin
Add-in Express Team Leader
Posted 07 Apr, 2020 01:25:36 Top