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

# TWinControl.DoKeyPress

Performs actions needed to handle a key press message for the control.

## Declaration

Source position: controls.pp line 2262

`protected function TWinControl.DoKeyPress(`
`var Message: TLMKey`
`):Boolean;`

## Arguments

`Message` |  | Control Notification message handled in the method.

## Function result

True if the key press was handled for the control.

## Description

DoKeyPress is a Boolean function used to handle a key press event received for the control. The return value is True if the character code in the specified Message is handled for the control.

DoKeyPress allows a TCustomForm instance in Parent with KeyPreview enabled to handle the notification message using its DoKeyPress method. If the character code is handled, the return value is set and no further actions are performed in the method.

The return value is False when standard events have been disabled by including csNoStdEvents in the ControlStyle property.

When not disabled, the KeyPress method is called using the character code in Message as an argument. If the character was handled in the OnKeyPress event handler, the return value is True.

DoKeyPress is called from the CNChar method when a CN_CHAR control notification message is received for the control.

## See also

TWinControl.OnKeyPress |  | Event handler signalled for character data entered by the user.
TWinControl.OnUTF8KeyPress |  | Handler for a character entered by the user.
TWinControl.DoUTF8KeyPress |  | Performs actions needed to handle a UTF-8-encoded key press message for the control.
TWinControl.CNChar |  | Handler for a key pressed notification; CNChar is sent by the widget before it has handled the key press itself.
TControl.ControlStyle |  | Contains style flags which control the features or behaviors enabled for the control.