Forms > Forms Assembly Interfaces > IControl > IControl.OnKeyDown
OnKeyDown(Sender: Object; Args: IKeyEventArgs);
Sender. The parameter that returns the component that has generated the event.
Args. The parameter that enables the user to determine event parameters.
The OnKeyDown event occurs if the component is focused and a keyboard key is pressed.
The event occurs on pressing the auxiliary keys: SHIFT, ALT, and CTRL.
If it is not necessary to recognize the auxiliary keys pressing, it is reasonable to use the OnKeyPress event.
Executing the example requires a form. Several components that can receive focus are placed on the form. The following procedure is used as a handler of the OnKeyDown event for all components:
Sub OnKeyDown(Sender: Object; Args: IKeyEventArgs);
Begin
If (Args.ShiftState = ShiftState.Ctrl) And (Args.Key = Keys.B) Then
Text := (Sender As IControl).Name;
End If;
End Sub OnKeyDown;
After executing the example, if CTRL+B was pressed in the area of any component, the name of this component is displayed in the form name.
See also: