GetAsyncKeyState(Key: Keys): Boolean;
Key. The key, which state is to be checked.
The GetAsyncKeyState method returns state (pressed or released) of a key outside the message queue.
The method returns True if the key passed by the Key parameter is the last pressed key independent on its current status.
Executing the example requires a form and a button named Button1 on the form.
Class TESTForm: Form
Button1: Button;
Sub StartOnClick(Sender: Object; Args: IMouseEventArgs);
Var
d: DateTime;
Begin
Self.BeginOperation("Execution");
d := DateTime.AddSeconds(DateTime.Now, 60);
While DateTime.Now < d Do
If WinApplication.GetAsyncKeyState(Keys.Escape) Then
Break;
End If;
End While;
Self.EndOperation;
End Sub StartOnClick;
End Class TESTForm;
Clicking the button starts a 60-second long process, during which the ESC button status is checked. If the button is pressed, the checking stops before the defined time ends.
See also: