home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / TURBOP.ZIP / INKEY.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1985-11-01  |  3.0 KB  |  86 lines

  1. program keytest; (* Testing the input of functionkeys in TURBO-PASCAL *)
  2.  
  3. (******************************************)
  4. (* Written by Wolfgang Siebeck, 72446,415 *)
  5. (* Date: 01/09/85                         *)
  6. (* With greetings from West Germany       *)
  7. (******************************************)
  8.  
  9. var
  10. key:      char;
  11. fkey:     boolean;
  12. special:  byte;
  13. n:        integer;
  14.  
  15. const
  16. keystr: string[40]=';<=>?@ABCDTUVWXYZ[\]^_`abcdefghijklmnopq';
  17.                (*   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ *)
  18.                (* These are the second codes of functionkeys *)
  19.  
  20. procedure inkey (var key: char; var fkey: boolean);
  21. begin
  22.     read (kbd, key);
  23.     fkey:=false;
  24.         if key = chr(27) then       (* maybe a functionkey    *)
  25.             if keypressed then
  26.             begin                   (* but only if keypressed *)
  27.                 fkey := true;       (* set the flag           *)
  28.                 read (kbd, key)     (* and read the 2nd code  *)
  29.             end
  30. end; (* inkey *)
  31.  
  32.  
  33. (*                 Demopart of the program                      *)
  34. (* This demo accepts functionkey 1..40 or normal keys and dis-  *)
  35. (* play the input on the screen. Functionkeys are displayed as  *)
  36. (* <F1> thru <F40> in high intensity, all other keys are dis-   *)
  37. (* played in low intensity. The alternate A..Z,0..9 are         *)
  38. (* trapped by the errorsound, but may be included by appending  *)
  39. (* their second codes to the const keystr.                      *)
  40. (* This version of inkey catches the difference between         *)
  41. (* hitting a functionkey and hitting <ESC> followed by a normal *)
  42. (* key.                                                         *)
  43. (****************************************************************)
  44.  
  45. begin
  46.     writeln ('                          Hit ^C to abort program.');
  47.     writeln;
  48.     lowvideo;
  49.     repeat
  50.  
  51.         repeat until keypressed;       (* loop for demo purpose *)
  52.         inkey (key,fkey);              (* call the kernel       *)
  53.         if not fkey then write (key)
  54.         else
  55.         begin
  56.             special := pos(key,keystr);
  57.             if special > 0 then
  58.             begin
  59.                 highvideo;
  60.                 write ('<F',special,'>');
  61.                 lowvideo;
  62.             end
  63.             else
  64.             begin
  65.                 write ('<NOT DEFINED>');
  66.                 for n:=100 to 500 do
  67.                 begin
  68.                     sound (n*10);
  69.                 end;
  70.                 nosound;
  71.             end;
  72.         end;
  73.     until (true=false);
  74. end.
  75.                                        *)
  76. (****************************************************************)
  77.  
  78. begin
  79.     writeln ('                          Hit ^C to abort program.');
  80.     writeln;
  81.     lowvideo;
  82.     repeat
  83.  
  84.         repeat until keypressed;       (* loop for demo purpose *)
  85.         inkey (key,fkey);              (* call the kernel       *)
  86.         if not f