procedure KeyDown(var Key: Word; var KeyChar: System.WideChar; Shift: TShiftState); virtual;
virtual void __fastcall KeyDown(System::Word &Key, System::WideChar &KeyChar, System::Classes::TShiftState Shift);
Executed when a key is pressed while this form has the input focus.
In FireMonkey framework KeyDown is the main method to process pressing of keys in forms. KeyDown is executed each time a key is pressed, when this form has the input focus. KeyDown is used internally: to activate menus and actions and to treat TAB requests to cycle through the children controls of this form. Editors can use KeyDown to add symbols into a text being edited.
You can override KeyDown to provide additional key treating in subclasses.
KeyDown has the following parameters:
Is the scan code of the pressed keyboard key or
Physical scan codes of the same key can differ under different platforms (Windows or iOS). Under FireMonkey framework, platform-specific units (for example FMX.Platform.Mac.pas) should translate native (iOS for FMX.Platform.Mac.pas unit) scan codes to the corresponding Windows codes defined in the UITypes unit. As the result
Keys of digits and letters -- independently of the selected input language and case of alphabetic keys -- have values corresponding to the '
Combinations of the
Is the pressed character (digit) or
If a pressed key combination can be handled as a printable character or digit, then
Determines the state of the CTRL, ALT, SHIFT, and CMD (only for Mac) keys at the moment you press the key.
KeyDown processes pressed keys according to the following algorithm:
- KeyDown first calls the IsDialogKey with the same parameters as those specified for KeyDown. The
KeyChar < ' 'or
Shiftis any of the CTRL, ALT or CMD keys. That is, if the
Shiftcombination identifies some control combination -- not a printable character. Otherwise, it returns
' 'character has the
$20ASCII value. ASCII values less than
$20identify control combinations.
- If IsDialogKey returns
IsDialogparameter, then the pressed key combination is passed, in the following order, to all child controls, menus and action lists in the form until this key combination is processed:
- To the control having focus.
- To the context menu of the control having focus.
- To all other menus and context menus in the form.
- To all other controls (not having focus) in the form.
- To action lists in the form and in all child components having assigned action list elements.
- To menus and action lists in all other forms.
- If the pressed key combination was processed during one of the previous steps, then KeyDown sets
Key = 0and
KeyChar = #0and terminates.
Key = vkTab, then KeyDown moves the focus to the next control in the controls "tab order" and terminates.
Key <> 0or
KeyChar <> #0, then KeyDown calls the KeyDown method of the control having focus and then calls the OnKeyDown event handler of the form if one is assigned.
- In the finally block, KeyDown stores the current date and time in the LastKeyPress and LastUserActive properties of the current application.