Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!ginosko!uunet!ucscc.ucsc.edu!gorn!filbo From: filbo@gorn.santa-cruz.ca.us (Bela Lubkin) Newsgroups: comp.lang.pascal Subject: Re: Clearing the keyboard buffer Message-ID: <50.filbo@gorn.santa-cruz.ca.us> Date: 4 Oct 89 07:30:08 GMT References: <48.filbo@gorn.santa-cruz.ca.us> <89276.021637TBC101@PSUVM.BITNET> Organization: R Pentomino Lines: 40 X-Claimer: I >am< R Pentomino! In article <89276.021637TBC101@PSUVM.BITNET> Thomas B. Collins, Jr. writes: >In article <48.filbo@gorn.santa-cruz.ca.us>, Bela Lubkin says: >> While KeyPressed Do Crud:=ReadKey; { Flush keyboard buffer } > If Crud = #0 then Crud := ReadKey; { Use in case of extended key code} >If the last character in the buffer was "extended" (Alt-something, >etc.), Keypressed will be false, but there will still be a value in >ReadKey to be read. If you forget to read this, it can cause trouble >later on... This isn't true in any version of Turbo Pascal that I've ever used... The keyboard handling code has always worked as follows: call the BIOS to check for a key. If it's not "extended", return the value. If it is "extended", save the value in a temporary variable and return the prefix value (ESC before Turbo 4.0, NUL after). KeyPressed has always been cognizant of the saved extended value. In fact, in Turbo 3.0 I used code such as: Read(Kbd,Ch); Extended:=(Ch=ESC) And KeyPressed; If Extended Then Read(Kbd,Ch); to read keystrokes, including extended characters. In 4/5/5.5: Ch:=ReadKey; Extended:=(Ch=NUL) And KeyPressed; If Extended Then Ch:=ReadKey; The check of KeyPressed isn't strictly necessary in 4/5/5.5 since it is very difficult to get the IBM BIOS to generate a NUL character from the keyboard, but is probably good practice anyway. On the other hand, it was necessary in Turbo 3.0 to prevent the program from blocking on the ESC key. The 3.0 code was susceptible to typed-ahead ESC "char" being interpreted as an extended sequence; in programs where that really mattered, I found the appropriate character in the runtime library and patched it to a NUL... Bela Lubkin * * filbo@gorn.santa-cruz.ca.us CIS: 73047,1112 @ * * ...ucbvax!ucscc!gorn!filbo ^^^ REALLY slow [months] R Pentomino * Filbo @ Pyrzqxgl (408) 476-4633 & XBBS (408) 476-4945