home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TURBO5.ZIP / INKEY.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1986-12-26  |  2.6 KB  |  80 lines

  1. program keydemo;
  2. {$C-}
  3. { By Orville Jenkins / Panther Associates / Dallas Ft. Worth                  }
  4. { These routines are for Public Domain and may be used for fun or PROFIT!!!   }
  5. var
  6.    SpecialKey : boolean;  { used in demo below }
  7.    command    : char;     { used in demo below }
  8.  
  9. { This program demonstrates a TURBO Pascal Procedure "INKEY".                 }
  10. { INKEY is a procedure which emulates the BASIC function "INKEY".             }
  11.  
  12. FUNCTION INKEY (var special : boolean; var KeyChar : char) : boolean;
  13. { Not-so-humbly offered to the TURBO Users Group by             }
  14. { Orville Jenkins / Panther Associates / Dallas-Ft. Worth       }
  15.  
  16. { INKEY returns TRUE if a key has been pressed.                               }
  17. { IF the parameter "special" is TRUE the character is one of the              }
  18. { two-code Keys such as F1-F10 etc. and the parameter "KEYCHAR"               }
  19. { is the second code which is what you're interested in.                      }
  20.  
  21. (* IMPORTANT: If you want "key-ahead" buffering of keystrokes                *)
  22. (* then you must turn off the compiler directive "C" by saying               *)
  23. (* {$C-}.  Without this, ie if you have {$C+} set then DOS will              *)
  24. (* throw away keystrokes which haven't yet been read in.                     *)
  25.  
  26. var
  27. dosrec : record
  28.              ax, bx, cx, dx, bp, si, di, ds, es, flags : integer;
  29.          end;
  30.  
  31. begin  {Function Inkey}
  32.    if keypressed then
  33.    begin
  34.       dosrec.ax := $0800;
  35.       msdos(dosrec);
  36.       keychar := chr(lo(dosrec.ax));
  37.       inkey := true;
  38.       if ord(keychar) = 27 then
  39.       begin
  40.          special := true;
  41.          dosrec.ax := $0800;
  42.          msdos(dosrec);
  43.          keychar := chr(lo(dosrec.ax));
  44.       end
  45.       else
  46.          special := false
  47.    end
  48.    else
  49.    begin { no character is ready }
  50.       inkey := false;
  51.       special := false;
  52.    end;
  53. end;  {Function Inkey}
  54.  
  55. Begin {Main Program}
  56.  
  57.    clrscr;
  58.    writeln('INKEY DEMO - Press any key - Press F-10 to quit');
  59.    writeln;
  60.    command := #00;
  61.  
  62.    repeat
  63.       if inkey(specialkey,command) then
  64.       begin
  65.          if specialkey then
  66.             writeln('That''s a SPECIAL key - the ascii code is ',ord(command) )
  67.          else
  68.             writeln('That''s a REGULAR key - the ascii code is ',ord(command));
  69.  
  70.          writeln;
  71.          writeln;
  72.          if command <> #68 then
  73.             writeln('INKEY DEMO - Pressss any key - Presss F-10 to quit ');
  74.          writeln;
  75.       end;
  76.    until command = #68; {F-10 key}
  77.  
  78. end.
  79.  
  80.