summaryrefslogtreecommitdiff
path: root/packages/rtl-console/tests/kbd1.pp
blob: b5b82085a334c420332f7774389d9201511c587f (plain)
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
program kbd1;

uses
  keyboard;

procedure ShowASCIIKey(C: Char);
begin
  Write('ASCII key #', Ord(C), ' - #$', HexStr(Ord(C), 2));
  if C = '''' then
    Write(' - ''''''''')
  else if (C >= #32) and (C <= #126) then
    Write(' - ''', C, '''')
  else if C < #32 then
    Write(' - ^', Chr(Ord(C) + Ord('@')));
  Writeln;
end;

procedure ShowUnicodeKey(WC: WideChar);
begin
  Writeln('Unicode key #', Ord(WC));
end;

procedure ShowKeyEvent(K: TKeyEvent);
begin
  case GetKeyEventFlags(K) and 3 of
    kbASCII:
      ShowASCIIKey(GetKeyEventChar(K));
    kbUniCode:
      ShowUnicodeKey(WideChar(GetKeyEventUniCode(K)));
    kbFnKey:
      Writeln('Function key ', FunctionKeyName(GetKeyEventCode(K)));
    kbPhys:
      Writeln('Physical key ', K and $FFFF, ' - $' + HexStr(K and $FFFF, 4));
  end;
  Writeln('Shift state: ', ShiftStateToString(K, True));
  if (GetKeyEventFlags(K) and kbReleased) <> 0 then
    Writeln('Released key event');
end;

var
  K: TKeyEvent;
begin
  InitKeyboard;
  Writeln('Press keys, press "q" to end.');
  repeat
    K:=GetKeyEvent;
    Write('Before translation: ');
    ShowKeyEvent(K);
    K:=TranslateKeyEvent(K);
    Write('After translation: ');
    ShowKeyEvent(K);
  until (GetKeyEventChar(K)='q');
  DoneKeyboard;
end.