is there a way to execute keyboard equivalents in a contextual menu ?

No, the topic is – at least on macOS – that every command should be in the main menu. And my example with the Xojo IDE was to show why and what happens when the command are not in the main menu: you cannot configure the keyboard shortcuts to your own needs.

Whatever. Nothing of that sort is in the HIG, and you are embarking a thread that was eminently simple into undue complexity IMO. But hey, if you enjoy it …

Not all users want to reconfigure all keyboard shortcuts. I would even bet that they are pretty rare.

The simple solution is to have a menu item with the keyboard shortcut and a menu item with the same name can be executed from the contextual menu. Problem solved. Couldn’t be easier.

Whatever, again.

[quote=292342:@Michel Bujardet]Once again, I will have to post a working project, right ?

BS if you tell me. Absolutely no need for putting anything in the menu bar.

See this project. It works, I tested (instead of making dogmatic statements) :
https://dl.dropboxusercontent.com/u/17407375/contextualmenushortcuts.xojo_binary_project

Cmd-E does trigger the menu option just fine.

Sigh. This mania of making things complex …[/quote]
Michel, many thanks for your example.
can you please test it for a textarea, as your example is for a pushbutton.
this was my first question.
thanks.

Just download again the project I updated from the same link.

Works like clockwork.

sorry, Michel, but if I clic on the textarea to select some text or not, if I press cmd-E I get a beep and not the “export” command.
if I right-clic I see the “export” command, and the cmd-E shortcut, I can execute it by clicking
but I cannot execute it by pressing cmd-E.

[quote=292342:@Michel Bujardet]See this project. It works, I tested (instead of making dogmatic statements) :
https://dl.dropboxusercontent.com/u/17407375/contextualmenushortcuts.xojo_binary_project

Cmd-E does trigger the menu option just fine.

Sigh. This mania of making things complex …[/quote]

Michel, are you using Windows?

In Linux and OS X Cmd-E does nothing

Wait wait wait.

If what you want is simply to obtain export by simple Cmd-E without displaying the contextual menu, it is a whole different ball game. To me the title of the thread implies a Contextual menu is displayed first.

Then you should check Cmd-E in TextArea keydown, verify that Cmd is pressed with Keyboard.AsyncCommand, and take whatever action you intend to do.

No need to display any menu, then.

Incidentally, you cannot use an invisible menu for that, it would not react to the shortcut.

[quote=292369:@Axel Schneider]Michel, are you using Windows?

In Linux and OS X Cmd-E does nothing[/quote]

You need to display the menu first with right-click. Otherwise it works just fine here under Sierra, with 2016R3. I don’t know, or frankly care, about Linux.

BTW I have again modified the project, and now pressing Cmd-E while TextArea is focused shows a “Cmd-E!” Msgbox.

https://dl.dropboxusercontent.com/u/17407375/contextualmenushortcuts.xojo_binary_project

Note for Windows users, if I remember right, Cmd is the Windows key.

[quote=292370:@Michel Bujardet]
Incidentally, you cannot use an invisible menu for that, it would not react to the shortcut.[/quote]

maybe Linux is then only OS where you can use an invisible MenuItem on TextArea.

https://www.dropbox.com/s/83srycafjirul15/tbold.zip?dl=1

Not exactly the same since there are a limited number of shortcuts without getting into two handed 4 modifier chorded shortcuts
But there are
cmd-f opens bottom pane to find pane
cmd-[ next pane (will open the bottom pane if it is not open)
cmd-] previous pane (will open the bottom pane if it is not open)
cmd-shift-f closes bottom pane regardless of what pane it is on

Apple doesn’t follow this at all
Right click the desktop and there’s “Change Desktop Background” which is definitely not in the menu bar

it is also true that I’ve never seen a keyboard shortcut in contextual menus of apple apps

“At all” is plain wrong. “In some cases” would be correct. No rule is applicable in all cases and this one exception doesn’t prove anything. The majority of commands in Apple’s own applications show in the main menu.

[quote=292393:@Norman Palardy]Not exactly the same since there are a limited number of shortcuts without getting into two handed 4 modifier chorded shortcuts
But there are
cmd-f opens bottom pane to find pane
cmd-[ next pane (will open the bottom pane if it is not open)
cmd-] previous pane (will open the bottom pane if it is not open)
cmd-shift-f closes bottom pane regardless of what pane it is on[/quote]
“Next Pane”/“Previous Pane” is complete nonsense when the content of each pane is not related to the others. Watch what you do when selecting a pane by the keyboard shortcuts: You must pause, look what pane is currently upfront, then decide if you have to go forward or backwards and then calculate if you have to press the keyboard shortcut once or twice. Look at the Edit, View, Find, Navigate menus in Xcode. You never need to touch the mouse or trackpad. And you can configure all these commands with your own keyboard shortcuts. So the correct way would be to have menu items for each pane. The menu of the IDE is so “empty” as the toolbar is. Not good UI design IMHO. Maybe Xojo should think about an IDE expert modus if they fear to over-challenge newbies with too many commands in the menu.

Note that I was not bringing up the IDE into this thread to discuss it, but to give an example, why Jean-Yves question would be easily solved with a keyboard shortcut in the main menu and a corresponding contextual menu with no shortcut. But it seems there are to many Windows programmers in this thread who feel attacted… and we all now that Windows software sucks and doesn’t follow any guidelines! I’m being sarcastic of course. Am I? Oh, I’m not.

Jean-Yves, does the latest project I posted do what you wanted to obtain ?

Xojo programmers coming from Mac may sometimes forget that Windows has very precise and very much adhered to design guidelines. Like for instance all menuItems in the bar can be attained with Alt-Letter without any special shortcut.

I feel the very word “Guidelines” in Apple’s Human Interface Guidelines, and Microsoft Windows Design Guidelines, unfortunately often cited but seldom completely read are precisely that. More a set of advices than an infrangible dogma.

I do wish, though, people who regularly look down at Windows, and often diss it when they ported without precaution their apps from Mac to Windows, had the good sense to study in more detail the current Microsoft Guidelines.

yes - thanks.
but for me the keyboard shortcuts in a contextual menu still “don’t work” .
you have to deal with the cmd-key yourself with a keydown event.
or implant the same command in the menubar to get fired.

OK. I will give up this time. “don’t work” means absolutely nothing if you dont care to explain in more details what you want to obtain.

Heck, I am not even sure you want a contextual menu in the first place as you say in the title.

WHAT do you want to obtain exactly ?

1 - A keyboard shortcut that NEVER shows a contextual menu, or
2 - a contextual menu that has a keyboard shortcut ?

Have you only looked at the code in the project I posted ? ? ?

I provided all that in the project. Please be kind enough to be a tad more precise in your answer. This is getting ridiculous.

Why do I waste time on such charades ?

I tried my best. Good bye, and good luck.

Maybe I’m wrong, I think he wants

an action that works by clicking context menu or using the shortcut.

[quote=292430:@Jean-Yves Pochez]yes - thanks.
but for me the keyboard shortcuts in a contextual menu still “don’t work” .
you have to deal with the cmd-key yourself with a keydown event.
or implant the same command in the menubar to get fired.[/quote]
Michel’s code is correct. You need to handle the keydown event in the control yourself.