Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a Delphi app shortcut with no corresponding menu item

I want to have a shortcut key combination (like Ctrl+Alt+D) in my app to invoke a function, but I don't want the shortcut to appear on any menu. Is it possible to have a shortcut available in your app that is otherwise invisible?

like image 564
rossmcm Avatar asked Jul 25 '10 20:07

rossmcm


2 Answers

you can use the OnShortCut event of the TApplicationEvents component to this task

check this code

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;
like image 194
RRUZ Avatar answered Nov 11 '22 15:11

RRUZ


Yes it's possible. You must add an Object of class TAction to your form. You can specify a keyboard shortcut for the Taction and then put your code in event OnExecute of the TAction.

Note that you cannot add a Taction directly to your form, you must put a TactionList on your form and then you can add a Taction to your TActionList.

like image 20
Giacomo Degli Esposti Avatar answered Nov 11 '22 16:11

Giacomo Degli Esposti