16: How can I
clear the keyboard type-ahead buffer?
A: Three methods are
usually suggested for solving this problem.
a) The first is to use something like
uses Crt;
while KeyPressed do ReadKey;
This kludge-type method has the disadvantage of requiring the Crt
unit. Also, in connection with procedures relying on ReadKey for
input, it may cause havoc on the programs logic.
b) The second method accesses directly the circular keyboard
buffer
var head : word absolute $0040:$001A;
tail : word absolute $0040:$001C;
procedure FLUSHKB; begin head := tail; end;
For a slightly different formulation of the same method see Michael
Tischer (1992), PC Intern System Programming, p. 462.
c) The third method is to call interrupt 21Hex (the MS-DOS
interrupt) with the ax register set as $0C00. This method has the
advantage of not being "hard-coded" like the second
method, and thus
should be less prone to incompatibility.