home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / MADTRB33.ZIP / KEYDEMO.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1986-02-07  |  5.6 KB  |  158 lines

  1. {$C-}
  2.  
  3. Program KeyDemo;
  4. type
  5.   BitType = 1..8;
  6. var
  7.   ToggleByte : byte absolute $40:$17;
  8.   ScreenSeg  : integer;
  9.   C, D       : char;
  10.   done       : boolean;
  11. {============================================================================}
  12. procedure illumination(N: BitType;light : boolean);    {Here I am "poking"   }
  13. var                                                    {an attribute byte    }
  14.   LocationCode : integer;                              {into the screen      }
  15.   Row,Col,Pos,LightLevel  : byte;                      {memory--15 is bright }
  16. begin                                                  {and 112 is reverse.  }
  17.   if light then LightLevel := 112 else LightLevel := 15;
  18.   Row := ((N-1) div 4) + 1;
  19.   Col := ((N-1) mod 4)*15;
  20.   for Pos := Col + 2 to Col + 15 do
  21.     begin
  22.       LocationCode := (Pos-1)*2 + (row-1)*160 + 1;
  23.       Mem[ScreenSeg:locationCode] := LightLevel;
  24.     end;
  25. end;
  26. {=======================================================================}
  27. procedure ToggleNames;
  28. begin
  29.   WriteLn('*   INSERT     *   CAPS LOCK  *    NUM LOCK  *  SCROLL LOCK *');
  30.   WriteLn('*     ALT      *    CONTROL   *   LEFT SHIFT *  RIGHT SHIFT *');
  31. end;
  32. {=======================================================================}
  33. procedure CheckStatus;             {ToggleByte is declared above at an }
  34. var                                {absolute location that happens to  }
  35.   N : BitType;                     {hold the status (on or off) of the }
  36.   checker : byte;                  {eight keys shown in its eight bits.}
  37. begin
  38.   checker := 1;
  39.   for N := 8 downto 1 do
  40.     begin
  41.       if ToggleByte and checker = checker then illumination(N,true)
  42.         else illumination(N,false);
  43.       checker := 2*checker;
  44.     end;
  45.   if ToggleByte and 10 = 10 then Done := true; {if left shift AND Alt are on}
  46. end;
  47. {=======================================================================}
  48. procedure GetKeys(var choice, EscChoice:char);      { This is a handy      }
  49. begin                                               { procedure.  It       }
  50.   repeat CheckStatus until KeyPressed or Done;      { waits for a key      }
  51.   EscChoice := chr(0);                              { to be pressed and    }
  52.   if not Done then                                  { reads it.  If the    }
  53.     begin                                           { keypressed function  }
  54.       read(Kbd,choice);                             { is still TRUE, it    }
  55.       if keypressed then read(Kbd,EscChoice);       { reads the Escape code}
  56.     end;
  57. end;
  58. {=======================================================================}
  59. procedure WhatKeys;
  60.   begin
  61.   GetKeys(C,D);
  62.   if not Done then
  63.     begin
  64.       gotoXY(10,10);
  65.       write('           ');
  66.       gotoXY(11,10);
  67.     if C = chr(27) then
  68.       begin
  69.         if D = chr(0) then write('Esc');
  70.         Case D of
  71.           ';': write('F1');
  72.           '<': write('F2');
  73.           '=': write('F3');
  74.           '>': write('F4');
  75.           '?': write('F5');
  76.           '@': write('F6');
  77.           'A': write('F7');
  78.           'B': write('F8');
  79.           'C': write('F9');
  80.           'D': write('F10');
  81.           'h': write('Alt-F1');
  82.           'i': write('Alt-F2');
  83.           'j': write('Alt-F3');
  84.           'k': write('Alt-F4');
  85.           'l': write('Alt-F5');
  86.           'm': write('Alt-F6');
  87.           'n': write('Alt-F7');
  88.           'o': write('Alt-F8');
  89.           'p': write('Alt-F9');
  90.           'q': write('Alt-F10');
  91.           'T': write('Shift-F1');
  92.           'U': write('Shift-F2');
  93.           'V': write('Shift-F3');
  94.           'W': write('Shift-F4');
  95.           'X': write('Shift-F5');
  96.           'Y': write('Shift-F6');
  97.           'Z': write('Shift-F7');
  98.           '[': write('Shift-F8');
  99.           '\': write('Shift-F9');
  100.           ']': write('Shift-F10');
  101.           '^': write('Ctrl-F1');
  102.           '_': write('Ctrl-F2');
  103.           '`': write('Ctrl-F3');
  104.           'a': write('Ctrl-F4');
  105.           'b': write('Ctrl-F5');
  106.           'c': write('Ctrl-F6');
  107.           'd': write('Ctrl-F7');
  108.           'e': write('Ctrl-F8');
  109.           'F': write('Ctrl-F9');
  110.           'g': write('Ctrl-F10');
  111.           'G': write('Home');
  112.           'H': write('Up');
  113.           'I': write('PgUp');
  114.           'K': write('Left');
  115.           'M': write('Right');
  116.           'O': write('End');
  117.           'P': write('Down');
  118.           'Q': write('PgDn');
  119.           'R': write('Ins');
  120.           'S': write('Del');
  121.           'w': write('Ctrl-Home');
  122.           'รค': write('Ctrl-PgUp');
  123.           's': write('Ctrl-LeFt');
  124.           't': write('Ctrl-Right');
  125.           'u': write('Ctrl-End');
  126.           'v': write('Ctrl-PgDn');
  127.           'r': write('Ctrl-prtsc');
  128.         end;  {case statement}
  129.       end   {if C = chr(27)}
  130.     else
  131.       case ord(C) of
  132.            9 : write('Tab');
  133.            8 : write('BackSpace');
  134.       else write(C);
  135.       end;   {case}
  136.     end;  {if not done}
  137. end;  {procedure GetKeys}
  138. {============================================================================}
  139. begin
  140.   IF (Mem[0000:1040] AND 48) <> 48 THEN ScreenSeg := $B800
  141.    ELSE ScreenSeg := $B000; {set screen memory segment to color or mono}
  142.   WriteLn('Play with the keys.  This program recognizes only SPECIAL');
  143.   WriteLn('keystrokes, such as the function and arrow keys.  It also');
  144.   WriteLn('tracks the toggles and shift keys.  Hit a key to start.');
  145.   WriteLn;
  146.   WriteLn('Press <Alt> and the left <shift> at once to quit.');
  147.   done := false;
  148.   repeat until KeyPressed;
  149.   ClrScr;
  150.   ToggleNames;
  151.   GotoXY(5,6);
  152.   Write('Press <Alt> and the left <shift> at once to quit.');
  153.   GotoXY(1,10);
  154.   Write('Key is->>> ');
  155.   repeat
  156.     WhatKeys
  157.   until Done;
  158. end.