Unit 'Controls' Package
[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] [#lcl]


Event handler signalled for key down keyboard events.


Source position: controls.pp line 2330

public property TWinControl.OnKeyDown : TKeyEvent
  read FOnKeyDown
  write FOnKeyDown;


OnKeyDown is a TKeyEvent property with the event handler signalled to handle a key down event for the control. The event handler receives keys including control and other non-visual keys. It is signalled (when assigned) from the KeyDown method.

The Sender argument contains the control for the key event. It must be cast to TControl or TwinControl type to access properties or methods specific to the descendent classes.

The Key argument contains the virtual keyboard constant for the key event (like VK_F1 or VK_NUMPAD5). It is a variable argument and can be modified in the event handler. Set Key to VK_UNKNOWN if the handler routine has performed the actions needed to handle the key event. Otherwise, Key is passed to other OnKeyDown handlers at the form or application level.

Shift is a set type which contains the modifiers for the key down event like: Ctrl, Shift, Alt, or Meta.

Remark: When a key is held down, the OnKeyDown event is re-triggered. The first re-triggered event occurs after approximately 500ms, and subsequent events cycle between 30ms and 50ms until the key is released.

Use OnKeyUp to perform actions needed when the key is released.

Use OnKeyPress or OnUTF8KeyPress to implement a handler routine for printable character values.

See also



Signals OnKeyDown event handlers (when assigned).



Event handler signalled when a key up event has occurred for the control.



Event handler signalled for character data entered by the user.



Defines an event handler for key events.

CT Web help

CodeTyphon Studio