appevents OnAppKeyDown event
Return to Introduction  Previous page  Next page
Applies to
acAppEvents component.  

  TacAppKeyEvent = procedure(Sender: TObject; var Key: Word; Shift: TShiftState; KeyName: String; RepeatedKeypress: Boolean) of object;  
property OnAppKeyDown: TacAppKeyEvent;  

The OnAppKeyDown event occurs when user presses any key in ANY window or control within the application. Use the OnAppKeyDown event to process any keypresses in whole program, even if the focus aimed to the control with different handle, in any form within current application process thread.  
For example, you would like to minimize your program when user press an "Esc" key. Then just insert following code to the OnAppKeyDown procedure handle:  
procedure TForm1.acAppEvents1AppKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState; KeyName: String; RepeatedKeypress: Boolean);  
  if not RepeatedKeypress and (Key = VK_ESCAPE) then  
tip The OnAppKeyUp handler can respond to all keyboard keys, including function keys and keys combined with the Shift, Alt, and Ctrl keys.  

KeyVirtual key code for pressed key (use VK_xx contants, for example, VK_ESCAPE = 27, VK_F1 = 112 and so forth);  
ShiftStateThe state of control keys like Shift, Ctrl and Alt;  
KeyNameThe name of pressed key;  
RepeatedKeypressIs the the key is down before the evvent occurs is sent. This is keypress is repeated if True.  

See also
OnAppKeyUp event.