-
Notifications
You must be signed in to change notification settings - Fork 1
/
unitformpressakey.pas
82 lines (66 loc) · 1.63 KB
/
unitformpressakey.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
unit UnitFormPressAKey;
// Copyright 2022-2024 Zoran Vučenović
// SPDX-License-Identifier: Apache-2.0
{$mode ObjFPC}{$H+}
{$i zxinc.inc}
interface
uses
Classes, SysUtils, CommonFunctionsLCL, Forms, Controls, Graphics, Dialogs,
StdCtrls;
type
TFormPressAKey = class(TForm)
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState);
procedure FormShow(Sender: TObject);
private
FKey: Word;
procedure AfterShow(Data: PtrInt);
public
class function ShowFormPressAKey(out AKey: Word): Boolean;
end;
implementation
{$R *.lfm}
{ TFormPressAKey }
procedure TFormPressAKey.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState
);
begin
FKey := Key;
ModalResult := mrOK;
end;
procedure TFormPressAKey.FormShow(Sender: TObject);
begin
AfterShow(2);
end;
procedure TFormPressAKey.FormDestroy(Sender: TObject);
begin
Application.RemoveAsyncCalls(Self);
end;
procedure TFormPressAKey.FormCreate(Sender: TObject);
begin
TCommonFunctionsLCL.FormToScreenCentre(Self);
end;
procedure TFormPressAKey.AfterShow(Data: PtrInt);
begin
TCommonFunctionsLCL.FormToScreenCentre(Self);
if Data > 0 then
Application.QueueAsyncCall(@AfterShow, Data - 1);
end;
class function TFormPressAKey.ShowFormPressAKey(out AKey: Word): Boolean;
var
F: TFormPressAKey;
begin
Result := False;
F := TFormPressAKey.Create(nil);
try
F.Caption := 'Choose PC key';
if F.ShowModal = mrOK then begin
AKey := F.FKey;
Result := True;
end;
finally
F.Free;
end;
end;
end.