问题
On a Firemonkey Form add a main menu and a single submenu item. Set the shortcut property for the submenu to Ctrl-A.
Is there anyway to intercept the Ctrl-A before it gets to the menu? It seems that the form OnKeyDown doesn't see it.
回答1:
The form checks if there are child components that want to handle the key. If the key is handled then that is the end of the story.
Here's a quick&dirty way that prevents the TMenuItem from handling the key, using an interposer.
type
TMenuItem = class(FMX.Menus.TMenuItem)
protected
procedure DialogKey(var Key: Word; Shift: TShiftState); override;
end;
procedure TMenuItem.DialogKey(var Key: Word; Shift: TShiftState);
begin
if (ssCtrl in Shift) and (Key = 65){A} then exit;
inherited;
end;
If you are using actions then you have to override the DialogKey function of the TActionList in the same way.
来源:https://stackoverflow.com/questions/25924994/how-to-intercept-menu-shortcut-event-in-firemonkey