From RAD Studio API Documentation
Jump to: navigation, search


procedure KeyDown(var Key: Word; var KeyChar: WideChar; Shift: TShiftState); virtual;


virtual void __fastcall KeyDown(System::Word &Key, System::WideChar &KeyChar, System::Classes::TShiftState Shift);


Type Visibility Source Unit Parent
FMX.Controls TControl


Provides a response when a key is pressed down while the control has the keyboard focus.

If the pressed key is the Applications key (Key = vkApps), then KeyDown shows the context menu of the control. Otherwise, KeyDown calls the OnKeyDown event handler if one is assigned.

TCommonCustomForm and descendant of TControl classes--like TCustomGrid--call KeyDown from their methods handling key pressing. They decode the message parameters into the key code, character code, and shift state. They pass them into the called KeyDown method in the Key, KeyChar, and Shift parameters, respectively:

Parameters Descriptions


Is the scan code of the pressed keyboard key or $0.

If a pressed key combination can be a shortcut, then Key <> 0 is a virtual key and KeyChar = #0.

Physical scan codes of the same key can differ under different platforms (Windows or iOS). Platform-specific units (for example FMX.Platform.Mac.pas) should translate native scan codes to corresponding Windows codes defined in the UITypes unit. For example,

vkReturn = $0D; { 13 } corresponds to the RETURN keyboard key.
vkF2 = $71; { 113 } corresponds to the F2 keyboard key.


Is the pressed character (digit) or #0.

If a pressed key combination can be treated as a printable character or digit, then Key = 0 and KeyChar contains a pressed symbol according to the current keyboard's input language, keyboard mode (CAPS LOCK and NUM LOCK keys), keyboard Shift state, and IME state. Editors can use this symbol to add into a text being edited.


Indicates which shift keys--SHIFT, CTRL, ALT, and CMD (only for Mac)--were down when the specified key was pressed with the control in focus.

If the control has successfully processed the pressed key combination and no additional processing is required, then KeyDown assigns Key = 0 and KeyChar = #0.

Override the protected KeyDown method to provide other responses when a key is down while the control has keyboard input focus.

See TCommonCustomForm.KeyDown for more information about parameters.

See Also