FMX.Forms.TCommonCustomForm.KeyDown
Delphi
procedure KeyDown(var Key: Word; var KeyChar: System.WideChar; Shift: TShiftState); virtual;
C++
virtual void __fastcall KeyDown(System::Word &Key, System::WideChar &KeyChar, System::Classes::TShiftState Shift);
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
procedure function |
public | FMX.Forms.pas FMX.Forms.hpp |
FMX.Forms | TCommonCustomForm |
Description
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:
Parameters | Descriptions |
---|---|
|
Is the scan code of the pressed keyboard key or The UITypes unit defines Virtual Keys providing symbolic constants for scan codes of keyboard keys. 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 ' If 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
IsDialog
parameter returnsTrue
ifKeyChar < ' '
orShift
is any of the CTRL, ALT or CMD keys. That is, if theKeyChar
andShift
combination identifies some control combination -- not a printable character. Otherwise, it returnsFalse
. The' '
character has the$20
ASCII value. ASCII values less than$20
identify control combinations. - If IsDialogKey returns
True
in theIsDialog
parameter, 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 = 0
andKeyChar = #0
and terminates.
- If
Key = vkTab
, then KeyDown moves the focus to the next control in the controls "tab order" and terminates. - If
Key <> 0
orKeyChar <> #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.