How to intercept Menu shortcut event in Firemonkey

人盡茶涼 提交于 2019-12-11 07:24:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!