如何在Firemonkey中拦截菜单快捷方式事件 [英] How to intercept Menu shortcut event in Firemonkey

查看:103
本文介绍了如何在Firemonkey中拦截菜单快捷方式事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Firemonkey表单上,添加一个主菜单和一个子菜单项.将子菜单的快捷方式属性设置为Ctrl-A.

On a Firemonkey Form add a main menu and a single submenu item. Set the shortcut property for the submenu to Ctrl-A.

在进入菜单之前,是否有拦截Ctrl-A的机会?似乎OnKeyDown表单看不到它.

Is there anyway to intercept the Ctrl-A before it gets to the menu? It seems that the form OnKeyDown doesn't see it.

推荐答案

该表单检查是否存在要处理该密钥的子组件.如果处理了密钥,那么故事就结束了.

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.

这是一种快速而肮脏的方法,可以防止TMenuItem使用插入器来处理密钥.

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;

如果要使用动作,则必须以相同的方式覆盖TActionListDialogKey功能.

If you are using actions then you have to override the DialogKey function of the TActionList in the same way.

这篇关于如何在Firemonkey中拦截菜单快捷方式事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆