[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] | Reference for unit 'Controls' (#lcl)

# TWinControl.OnKeyDown

Event handler signalled for key down keyboard events.

## Declaration

Source position: controls.pp line 2349

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

## Description

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.

Remark:

Some key combinations are used as global shortcut keys for a given widgetset (QT, GTK, Cocoa), window manager (KDE, Gnome, Windows), or display protocol (X11, Wayland, WinAPI). These global shortcuts are platform-specific and generally perform system navigation or window management. They may be handled by the desktop / window manager and not forwarded to an application, form, or control. Some common examples include: Ctrl+F4, Alt+F4, Ctrl+Command+Q, and others. For more details, please refer to the developer documentation for the platform (widgetset) or desktop window manager.

- https://docs.kde.org/stable5/en/khelpcenter/fundamentals/kbd.html
- https://help.gnome.org/users/gnome-help/stable/shell-keyboard-shortcuts.html.en
- https://developer.gnome.org/hig/reference/keyboard.html
- https://support.microsoft.com/en-us/windows/keyboard-shortcuts-in-windows-dcc61a57-8ff0-cffe-9796-cb9706c75eec
- https://support.apple.com/en-us/102650
- https://en.wikipedia.org/wiki/Table_of_keyboard_shortcuts#Comparison_of_keyboard_shortcuts

## See also

TWinControl.KeyDown |  | Signals OnKeyDown event handlers (when assigned).
TWinControl.OnKeyUp |  | Event handler signalled when a key up event has occurred for the control.
TWinControl.OnKeyPress |  | Event handler signalled for character data entered by the user.
TKeyEvent |  | Defines an event handler for key events.