{@@@@@@@@@@@ copyright (C) 1984 by Neil J. Rubenking @@@@@@@@@@@@@@@@@@@@@@@@
The purchaser of these procedures and functions may include them in COMPILED
programs freely, but may not sell or give away the source text.

   If the function KeyBoard is invoked with the [W]ait parameter, it
   WAITS for a key to be pressed.  If [N]o wait, it returns zero if
   there's nothing in the keyboard buffer, or calls KeyBoard('W') if
   there is something.  The return is an integer--its low byte is the
   ASCII code of the key pressed (zero if a "special" code key) and
   its high byte is the scan code.  If you call for [N]o wait and no
   key was pressed, both high and low bytes will be zero.

   Note that the file SCANCODE.DAT contains a screen picture of the
   keyboard scan codes and a chart of the special codes.

}
{$I regpack.typ}
{$I keyboard.lib}
var
  TheseCodes          : integer;
  ASCIIcode, ScanCode : byte;
  ThisCharacter       : char;

begin
  WriteLn('Press a key to begin.  Press Escape to end.');
  repeat
    TheseCodes := KeyBoard('W');
    ASCIIcode  := (TheseCodes shl 8) shr 8;
    ScanCode   := TheseCodes shr 8;

    { NOTE: I have used "shl" and "shr" here to get the high and low bytes.
      These will be familiar to Assembly language programmers. They mean
      "shift left" and "shift right".  "shl <x>" is a left shift of <x> bits.
      The highest bits are "pushed off" the top end, and <x> zeroes are
      tacked on the low end.  Thus, if a 16-bit integer is shown by
      HHHHHHHHLLLLLLLL, (the Hs begin the High 8 bits and the Ls the Low)
      after a "shl 8" it will look like "LLLLLLLL00000000", and after being
      shifted 8 right again, it will be "00000000LLLLLLLL".  If we just
      "shr 8" to start with, we get "00000000HHHHHHHH".  SHR and SHL are
      invaluable any time you need to do individual bit manipulation.}

    if ASCIIcode = 0 then
      WriteLn('Character is "special"')
    else WriteLn('Character is ',chr(ASCIIcode));
    WriteLn('Scan Code is ',ScanCode);
    WriteLn;
  until (ASCIIcode = 27) and (ScanCode = 1);
end.r);           { Set offset of buffer.