Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!news.funet.fi!uwasa.fi!ts From: ts@uwasa.fi (Timo Salmi) Newsgroups: comp.lang.pascal Subject: Re: Preset KeyPressed Function? Message-ID: <1990Nov26.075535.17834@uwasa.fi> Date: 26 Nov 90 07:55:35 GMT References: <9011251958.AA08961@euler.Berkeley.EDU> <1728@umriscc.isc.umr.edu> Organization: University of Vaasa Lines: 43 In article <1728@umriscc.isc.umr.edu> mcastle@mcs213a.cs.umr.edu (Mike Castle) writes: ... much deleted ... > >Procedure ClearKbd; > >Type > Ch : Char; > >Begin > While KeyPressed do Ch:=ReadKey; >End; > >That looks like it should do it..... Allow me to add some material from my /ts/pc/tsfaq14.arc FAQ collection. The third method below (which should be the most robust) can be found preprogrammed in my /pc/ts/tspas22.arc Turbo Pascal units at uwasa.fi archives. 16. ***** Q: 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; var dummy : char; while KeyPressed do dummy := 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; c) The third method is to call interrupt 21Hex (the MsDos 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. ................................................................... Prof. Timo Salmi (Moderating at anon. ftp site 128.214.12.3) School of Business Studies, University of Vaasa, SF-65101, Finland Internet: ts@chyde.uwasa.fi Funet: gado::salmi Bitnet: salmi@finfun