Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!osu-20.ircc.ohio-state.edu!laufman-h From: LAUFMAN-H@osu-20.ircc.ohio-state.edu (Harry Laufman) Newsgroups: comp.lang.pascal Subject: Readkey without "use crt" (Was Re: Strobing the keyboard) Keywords: keyboard, read, keypressed Message-ID: <12544333713034@osu-20.ircc.ohio-state.edu> Date: 22 Nov 89 20:03:08 GMT Sender: news@tut.cis.ohio-state.edu Organization: The Ohio State University, Columbus, Ohio Lines: 63 KeyBoard reading without Unit CRT. I have used FUNCTION KEYHIT instead of KEYPRESSED for quite awhile now since it is demonstrably faster. On reading the "Readkey without Unit CRT" query, it seemed it could be done by reading memory directly with the Turbo Mem and MemW (byte and word based) arrays. With the help of the cited manual I pieced together a Turbo 5.5 compiled code which seems to work OK. I did find I had to re-assign the keyboard buffer head address to the keyboard buffer tail address. Apparently the Turbo call to ReadKey does this. Good Luck, Harry LAUFMAN-H@osu-20.ircc.ohio-state.edu Reference and source code follow: -------------------------------------------------------------------------- DOS TECHNICAL INFORMATION Programming Technical Reference - IBM Copyright 1988, Dave Williams { found a DOSTECH.ZIP on many BBSs } { many lines omitted } Reserved Memory Locations in the IBM PC addr. size description { many lines omitted } 40:17 byte keyboard flag byte 0 (see int 9h) bit 7 insert mode on 3 alt pressed 6 capslock on 2 ctrl pressed 5 numlock on 1 left shift pressed 4 scrollock on 0 right shift pressed 40:18 byte keyboard flag byte 1 (see int 9h) bit 7 insert pressed 3 ctrl-numlock (pause) toggled 6 capslock pressed 2 PCjr keyboard click active 5 numlock pressed 1 PCjr ctrl-alt-capslock held 4 scrollock pressed 0 40:19 byte storage for alternate keypad entry (not normally used) 40:1A word pointer to keyboard buffer head character 40:1C word pointer to keyboard buffer tail character 40:1E 32bytes 16 2-byte entries for keyboard circular buffer, read by int 16h { many lines omitted } ----------------------------------------------------------------------------- program readmem; {** This could certainly be tersed up with lose of clarity **} var Address : Word; AChar : Char; Function KeyHit:Boolean; begin KeyHit := Mem[$0040:$001A] <> Mem[$0040:$001C] end; { Kbd Buffer Head <> Kbd Buffer Tail } begin Writeln('*** Begin ***'); Achar := 'a'; Repeat If Keyhit then begin Address := MemW[$0040:$001A]; { Where the Kbd Buffer Head is } AChar := Chr(MemW[$0040:Address]); { What it is } Mem[$0040:$001A] := Mem[$0040:$001C];{ Set Head = Tail } writeln(AChar); { See what we got } end; Until AChar = 'x'; { A way out } Writeln('*** End ***'); readln; { Wait for } end.