home *** CD-ROM | disk | FTP | other *** search
- {The following is a way of fetching the SCANCODE of a key pressed on
- the IBM PC. This will only work with BORLAND INTERNATIONAL's
- TURBO PASCAL which has a facility for both BIOS & DOS interrupt
- handling. The DOS interrupt read-char function was not employed here
- since it requires 2 calls to get the required values:
- [Scan Code in AH & ASCII code in AL].
- Andy Decepida}
-
- program IntrSample;
-
- var
- ch : char;
- SCode : integer;
- Quitting : boolean;
-
-
- {The guts of the subroutine to fetch the scancode via with
- TURBO PASCAL' Interrupt facility follows
-
- =====================================================================}
-
- procedure GetScanCode (var ScanCode : integer);
-
- type
- regpack = record
- ax, bx, cx, dx, bp, si, ds, es, flags : integer;
- end;
-
- var
- recpack : regpack; {assign record}
- ah, al : byte;
-
- begin
- ah := $0; {read char function}
- with recpack do
- ax := ah shl 8 + al;
- intr ($16, recpack); {call keyboard I/O ROM call}
- ScanCode := recpack.ax;
- end;
-
- {subroutine ends here
- =====================================================================}
-
- begin
- Quitting:=false;
- repeat
- write (' ■');
- GetScanCode (SCode); {an example of calling GetScanCode}
- if SCode = 7181 then {an example of testing
- what GetScanCode returns
- n.b.: 7181 happens to be
- the scan code for the RETURN key}
- quitting := true
- else
- writeln (' ',SCode);
- until Quitting;
- end.