Delphi - Using the TApplicationEvents OnShortCut event to detect Alt+C key presses

前端 未结 2 531
小蘑菇
小蘑菇 2021-02-10 07:51

I am using TApplicationEvents OnShortCut event to get application keyboard short cuts in a Delphi program.

Using the following code:

procedure TForm1.App         


        
相关标签:
2条回答
  • 2021-02-10 08:07

    Like so:

    procedure TForm1.ApplicationEvents1ShortCut(var Msg: TWMKey;
      var Handled: Boolean);
    begin
      if (Msg.CharCode = Ord('C'))
        and (HiWord(Msg.KeyData) and KF_ALTDOWN <> 0)
      then begin
        ShowMessage('Alt+C pressed!') ;
        Handled := TRUE;
      end;
    end;
    

    Please note that using Alt and some key only is a bad choice for a shortcut, as the system uses these to activate menu items or dialog controls.

    0 讨论(0)
  • 2021-02-10 08:22

    Or you can create simple TAction, they eats shortcuts before others.

    0 讨论(0)
提交回复
热议问题