home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / TURBOINT.ZIP / INTR.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1985-12-28  |  1.8 KB  |  57 lines

  1. {The following is a way of fetching the SCANCODE of a key pressed on
  2.  the IBM PC.  This will only work with BORLAND INTERNATIONAL's
  3.  TURBO PASCAL which has a facility for both BIOS & DOS interrupt
  4.  handling.  The DOS interrupt read-char function was not employed here
  5.  since it requires 2 calls to get the required values:
  6.                    [Scan Code in AH & ASCII code in AL].
  7.  Andy Decepida}
  8.  
  9. program IntrSample;
  10.  
  11. var
  12.     ch : char;
  13.     SCode : integer;
  14.     Quitting : boolean;
  15.  
  16.  
  17. {The guts of the subroutine to fetch the scancode via with
  18.      TURBO PASCAL' Interrupt facility follows
  19.  
  20. =====================================================================}
  21.  
  22. procedure GetScanCode (var ScanCode : integer);
  23.  
  24. type
  25.     regpack = record
  26.                  ax, bx, cx, dx, bp, si, ds, es, flags : integer;
  27.               end;
  28.  
  29. var
  30.     recpack : regpack;       {assign record}
  31.     ah, al : byte;
  32.  
  33. begin
  34.      ah := $0;               {read char function}
  35.      with recpack do
  36.          ax := ah shl 8 + al;
  37.      intr ($16, recpack);    {call keyboard I/O ROM call}
  38.      ScanCode := recpack.ax;
  39. end;
  40.  
  41. {subroutine ends here
  42. =====================================================================}
  43.  
  44. begin
  45.      Quitting:=false;
  46.      repeat
  47.          write (' ■');
  48.          GetScanCode (SCode); {an example of calling GetScanCode}
  49.          if SCode = 7181 then {an example of testing
  50.                                what GetScanCode returns
  51.                                n.b.: 7181 happens to be
  52.                                the scan code for the RETURN key}
  53.              quitting := true
  54.          else
  55.              writeln (' ',SCode);
  56.      until Quitting;
  57. end.