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

# TWinControl.KeyDown

Signals OnKeyDown event handlers (when assigned).

## Declaration

Source position: controls.pp line 2270

`protected procedure TWinControl.KeyDown(`
`var Key: Word;`
`Shift: TShiftState`
`); virtual;`

## Arguments

`Key` |  | Numeric key code examined and handled in the method.
`Shift` |  | Shift, Ctrl, or Alt modifier for the key.

## Description

KeyDown is a method used to signal the assigned OnKeyDown event handler(s) for the control. It provides arguments with the virtual key code and the state modifiers for the TKeyEvent type.

KeyDown signals the OnKeyDown event handler (when assigned). The handler routine can modify the Key argument if it is handled (or discarded) in the event handler. Set Key to VK_UNKNOWN (0) in the handler routine if the key event is either applied or discarded by the handler.

When Key has a non-zero value - because OnKeyDown was not assigned or did not handle the key - DoCallKeyEventHandler is called to check other chtOnKeyDown handlers added to the control using AddHandler or AddHandlerOnKeyDown.

KeyDown is called from the KeyDownBeforeInterface method. It occurs after the Application, any forms with KeyPreview enabled, and the active DragManager have examined and possibly handled the key event.

See KeyUp for the actions performed when the key is released.

## See also

TWinControl.OnKeyDown |  | Event handler signalled for key down keyboard events.
TWinControl.KeyUp |  | Signals the OnKeyUp event handler (when assigned).
TWinControl.KeyDownBeforeInterface |  | Allows the application, parent forms, or control to handle key preview before the LCL interface.
TControl.DoCallKeyEventHandler |  | Passes key events for the specified type to the handlers added to the control.
TControl.AddHandler |  | Adds a notification handler for the specified control handler type.
TControl.AddHandlerOnKeyDown |  | Adds the specified OnKeyDown event handler.
TKeyEvent |  | Defines an event handler for key events.
TControlHandlerType |  | Notification handler types.
TCustomForm.KeyPreview |  | Allows the form to intercept keystrokes in child controls.
TCustomForm.IsShortcut |  | Determines whether the specified message contains a shortcut or accelerator key.
TApplication.IsShortcut |  | Checks whether a handler is available for the shortcut key in the message.
Application |  | The TApplication singleton.