Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!pilchuck!seahcx!phred!brianr From: brianr@phred.UUCP (Brian Reese) Newsgroups: comp.lang.pascal Subject: Re: Clearing the keyboard buffer Message-ID: <2774@phred.UUCP> Date: 3 Oct 89 18:51:51 GMT References: <1169@krafla.rhi.hi.is> <708@thor.wright.EDU> <246@usna.MIL> Reply-To: brianr@phred.UUCP (Brian Reese) Organization: <246@usna.MIL>o Lines: 47 In article <246@usna.MIL> baldwin@cad.usna.mil (J.D. Baldwin) writes: >In article <708@thor.wright.EDU> bkottman@wright.EDU (Brett Kottmann) writes: >>in article <1169@krafla.rhi.hi.is>, karlth@rhi.hi.is (Karl Thoroddsen) says: >>>[asks how to clear the keyboard input buffer in Turbo 4.0] >> >> readln; >> or >> readln(garbage_variable); >> >>should do it. Although I'm shure there is a more elegant solution. > >Well, I'm a Turbo 5.0 man myself (never used 4.0), but I can't imagine that >this would work. If there are characters in the input buffer *after* the >last, or if there has been no . Also, Brett's solution has the >(possibly extremely serious) defect that it will pause and ask for an >unintended input if there is nothing in the input buffer. >My solution: > > while KeyPressed do ReadKey; > > _, J. D. Baldwin, Comp Sci Dept |+| say, I am quite prepared not only to Hello all, I agree with J.D. in that Brett's solution could pause for unintended input should the buffer be empty. In fact, I e-mailed a solution similar to J.D.'s to the original poster. However, ReadKey is a function which returns a value and must be assigned to a variable, i.e. var Ch : char; while KeyPressed do Ch := ReadKey; I've used this many times, but often wondered if there is an interrupt to do the same thing. Does anyone out there know? Brian "I've learned C. It's an extremly powerful language that allows a programmer to do incredibly stupid things! I still love my Pascal compiler!!!!" -- Brian Reese uw-beaver!pilchuck!seahcx!phred!brianr Physio Control Corp., Redmond, Wa. brianr@phred.UUCP "Do not write on this line. This line has been left blank intentionally."