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 ESCAPE button status is checked. If the button is pressed, the checking stops before the defined time ends.
Executing the example requires a .NET form with a button on the form. The form is set as a startup object for the .NET assembly.
Imports Prognoz.Platform.Interop.Ui;
Public Partial Class TESTForm: Prognoz.Platform.Forms.Net.ForeNetForm
Public Constructor TESTForm();
Begin
InitializeComponent();
End Constructor;
Private Sub button1_Click(sender: System.Object; e: System.EventArgs);
Var
d: DateTime;
WinAppCls: WinApplicationClass = New WinApplicationClassClass();
Begin
Self.BeginOperation("Execution");
d := DateTime.Now.AddSeconds(60);
While DateTime.Now < d Do
If WinAppCls.GetAsyncKeyState(Prognoz.Platform.Interop.Forms.Keys.ksEscape) Then
Break;
End If;
End While;
Self.EndOperation();
End Sub;
End Class;
Clicking the button starts a 60-second long process, during which the ESCAPE button status is checked. If the button is pressed, the checking stops before the defined time ends.
See also: