We know that if we set a shortcut (for example, Ctrl + F2) to a TMenuItem, the menu item will be executed automatically once the shortcut specified is pressed, and the shortcut description will be also shown when the menu is displayed.
But is there a way to have the shortcut descriptions visible on the menu items but make the menu don't respond to the shortcuts automatically?
You might ask me why I want this, here is the situation:
In a multiple document (like firefox's multiple tabs) program, there are multiple instances of TPopupMenu thus multiple TMenuItem objects have the same shortcuts, but I only want the menuitems in the active document window respond to the shortcuts.
Edit 1: Sorry, I wanted to simplify my question and I described it wrongly - actually, I use TActionList and link the actions to menu items.
Edit 2: Just found: I think I can use TApplicationEvents.OnShortCut Event to intercept the shortcuts before they are being dispatched to the menus/actions... I'll try and will update my questions when I get a result.
Use the tab (#9) character to indicate the shorcut part of the text in standard menus. You can set the Caption
property of the menu item or the action component that the menu item is bound to by either editing the 'dfm' or at run-time to include the tab character:
procedure TForm1.FormCreate(Sender: TObject);
begin
Action1.Caption :=
Action1.Caption + #9 + ShortCutToText(ShortCut(VK_F2, [ssCtrl]));
Unless you also assign to the ShortCut
property itself of the menu item or the action, the click/execute event will not be fired.
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