File: testkbd.pas

package info (click to toggle)
fpc 0.99.13-19991013-4
  • links: PTS
  • area: main
  • in suites: potato
  • size: 23,104 kB
  • ctags: 9,760
  • sloc: pascal: 253,711; ansic: 5,236; makefile: 3,855; yacc: 2,016; lex: 707; asm: 526; xml: 443; sh: 200; perl: 87; sed: 21; csh: 12; cpp: 1
file content (38 lines) | stat: -rw-r--r-- 766 bytes parent folder | download | duplicates (2)
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
uses
  Keyboard;

function hexstr(val : longint;cnt : byte) : string;
const
  HexTbl : array[0..15] of char='0123456789ABCDEF';
var
  i : longint;
begin
  hexstr[0]:=char(cnt);
  for i:=cnt downto 1 do
   begin
     hexstr[i]:=hextbl[val and $f];
     val:=val shr 4;
   end;
end;

var
  Key: TKeyEvent;
  Chr: Char;

begin
  InitKeyboard;
  Chr := #0;
  while Chr <> #27 do begin
    Key := GetKeyEvent;
    writeln('KeyEvent: ',hexstr(key,8));
    Key:=translatekeyevent(key);
    if IsFunctionKey(Key) then begin
      WriteLn('Function key was pressed, Code: ', GetKeyEventCode(Key));
     end
     else begin
      Chr := GetKeyEventChar(Key);
      WriteLn('Normal key was pressed, character: ', Chr, ' (', Ord(Chr), ')');
    end;
  end;
  DoneKeyboard;
end.