Delphi - using the TApplicationEvents OnShortCut event to detect Alt + C keystrokes

I use the TApplicationEvents OnShortCut event to get short keyboard shortcuts for an application in a Delphi program.

Using the following code:

procedure TForm1.ApplicationEvents1ShortCut(var Msg: TWMKey; var Handled: Boolean) ; begin if (Msg.CharCode = VK_F9) then begin ShowMessage('F9 pressed!') ; Handled := True; end; end; 

Question:

How to determine when the ALT C button is pressed?

+4
source share
2 answers

Same:

 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; 

Note that using the Alt keys and some keys is a poor choice for a shortcut, as the system uses them to activate menu items or dialog box controls.

+7
source

Or you can create a simple TAction, they eat shortcuts in front of others.

+1
source

All Articles