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
|
{
Keyboard example for the PTCPas library
This source code is in the public domain
}
program KeyboardExample3;
{$MODE objfpc}
uses
ptc;
procedure DumpKey(AKey: IPTCKeyEvent);
begin
Writeln('Code=', AKey.Code:3, ', Unicode=$', HexStr(AKey.Unicode, 4),
', Press=', AKey.Press:5, ', Shift=', AKey.Shift:5, ', Alt=', AKey.Alt:5,
', Control=', AKey.Control:5);
end;
var
console: IPTCConsole;
format: IPTCFormat;
key: IPTCKeyEvent;
Done: Boolean;
begin
try
try
{ create console }
console := TPTCConsoleFactory.CreateNew;
{ enable key release events }
console.KeyReleaseEnabled := True;
{ create format }
format := TPTCFormatFactory.CreateNew(32, $00FF0000, $0000FF00, $000000FF);
{ open the console }
console.open('Keyboard example 3', format);
{ main loop }
Done := False;
repeat
{ check for key press/release }
while console.KeyPressed do
begin
console.ReadKey(key);
case key.code of
PTCKEY_ESCAPE:
begin
Done := True;
Break;
end;
else
DumpKey(key);
end;
end;
{ update console }
console.update;
until Done;
finally
if Assigned(console) then
console.close;
end;
except
on error: TPTCError do
{ report error }
error.report;
end;
end.
|