home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / TPGET.ZIP / GETCHAR.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1984-12-07  |  2.4 KB  |  73 lines

  1. Program Buffered_Keyboard_Routine;
  2.  
  3. {   This Routine Calls DOS when a key is pressed to get a character. }
  4. { This allows full access to the extended key codes. Turbo normally  }
  5. { Replaces the Nul ASCII code of 0 with an esc. This makes the use   }
  6. { of the Esc key at the same time as the extended keys impossible.   }
  7. { The Demo with the routine Beeps every so often when a character    }
  8. { has not been typed. Extended characters are printed in highlight.  }
  9. { Written by: Kevin Bales   Atlanta,Georgia 404-321-3841             }
  10. { ***NOTE: The DOS routine used has the side effect of having Ctrl-S }
  11. {          and Ctrl-C having the same effects as in DOS. Ctrl-S      }
  12. {          Pauses, and Ctrl-C Interupts like a Ctrl-Break .          }
  13.  
  14. Var
  15.  Ch:         Char;
  16.  Extended:   Boolean;
  17.  Count:      Integer;
  18.  
  19. Procedure GetChar(VAR Ch: Char; VAR Extended: Boolean);
  20. { This Procedure acts simliar to the BASIC "Inkey$" command. }
  21. { If no Character is in the Keyboard buffer, then Ch is set  }
  22. { to ASCII code 0. If the character in the buffer is a char  }
  23. { with an extended scan code, then Extended is set to true,  }
  24. { and Ch is equal to the characters scan code.               }
  25. Type
  26.  Registers = Record
  27.               AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags: Integer;
  28.              End;
  29. Var
  30.  Reg: Registers;
  31.  AL:  Integer;
  32. Begin
  33. Ch:=#0; Extended:=False;
  34. If KeyPressed Then
  35.  Begin
  36.  Reg.Ax:=$0800;                { -Set AH as $8 for Dos Function call      }
  37.  Intr($21,Reg);                { -Calls Interupt $21 for Dos Fucntion call}
  38.  AL:=(Reg.AX AND $00FF);       { -Derive AL from AX                       }
  39.  Ch:=Chr(AL);                  { -Set Ch to character to AL               }
  40.  If Ch=#0 then
  41.   Begin                       { Routine to get extended character scan code }
  42.   Reg.Ax:=$0800;
  43.   Intr($21,Reg);
  44.   Ch:=Chr((Reg.AX AND $00FF));
  45.   Extended:=True;
  46.   End;
  47.  End;
  48. End;
  49.  
  50.  
  51. Begin
  52. LowVideo;
  53. Write('Enter Line:');
  54. Repeat
  55.  GetChar(Ch,Extended);
  56.  If Ch<>#0 then
  57.   Begin
  58.   If Extended then NormVideo Else LowVideo;
  59.   If Ch=#8 then Write(#8,' ',#8)
  60.    Else Write(Ch);
  61.   End
  62.  Else
  63.   Begin
  64.   Count:=Count+1;
  65.   If Count=5000 then
  66.    Begin
  67.    Count:=0;
  68.    Sound(1000); Delay(100); NoSound;
  69.    End;
  70.   End;
  71. Until Ch=#13;
  72. End.
  73.