IKeyPreviewEventArgs.KeyMessage

Syntax

KeyMessage: KeyMessageType;

Description

The KeyMessage property returns a value that indicates why the OnKeyPreview event was generated.

Comments

The OnKeyPreview event occurs before such events as OnKeyDown, OnKeyPress, and OnKeyUp. Currently, the KeyMessage property is used to check, before which event the OnKeyPreview event occurred.

Example

Executing the example requires a form and the EditBox component named EditBox1 on it. This procedure is set as a handler of the OnKeyPreview event for the EditBox1.

    Sub EditBox1OnKeyPreview(Sender: Object; Args: IKeyPreviewEventArgs);
    Begin
        If (Args.KeyMessage = KeyMessageType.KeyUp) And (Args.Key = Keys.A) Then
            Debug.WriteLine("Cancel the OnKeyUp event for the A key);
            Args.Cancel := True;
        End If;
    End Sub EditBox1OnKeyPreview;

After executing the example, if the A key was pressed and released in the area of the component, when the text was entered, only the OnKeyDown and OnKeyPress events are handled. The handling of the OnKeyUp further event is canceled.

See also:

IKeyPreviewEventArgs