创建没有相应菜单项的Delphi应用程序快捷方式

ros*_*mcm 7 delphi menu shortcut taction tmenuitem

我想在我的应用程序中有一个快捷键组合(如Ctrl + Alt + D)来调用一个函数,但我不希望快捷方式出现在任何菜单上.您的应用程序中是否可以使用其他不可见的快捷方式?

RRU*_*RUZ 12

您可以OnShortCutTApplicationEvents组件的事件用于此任务

检查此代码

procedure TForm1.ApplicationEvents1ShortCut(var Msg: TWMKey;
  var Handled: Boolean);
begin
  if (Msg.CharCode = Ord('D')) and (HiWord(Msg.KeyData) and KF_ALTDOWN <> 0) and  (GetKeyState(VK_CONTROL) < 0) then
  begin
    ShowMessage('Ctrl+Alt+D Pressed') ;
    Handled := true;
  end;
end;
Run Code Online (Sandbox Code Playgroud)

  • 如果您已经在表单上的其他操作中使用TActionList,则只需添加具有所需快捷方式的另一个TAction就会更加优雅并提高可读性.(根据Giacomo Degli Esposti的建议) (2认同)

Gia*_*sti 8

是的,这是可能的.您必须在表单中添加类TAction的对象.您可以为Taction指定键盘快捷键,然后将代码放在TAction的事件OnExecute中.

请注意,您无法直接向表单添加Taction,您必须在表单上放置TactionList,然后才能将Taction添加到TActionList.