Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!chad From: chad@csd4.csd.uwm.edu (D. Chadwick Gibbons) Newsgroups: comp.lang.pascal Subject: Re: Reading the keyboard Keywords: keyboard scancodes Message-ID: <3950@csd4.csd.uwm.edu> Date: 23 Aug 89 03:28:40 GMT References: <835@eutrc3.urc.tue.nl> Sender: news@csd4.csd.uwm.edu Reply-To: chad@csd4.csd.uwm.edu (D. Chadwick Gibbons) Followup-To: comp.lang.pascal Distribution: usa Organization: University of Wisconsin-Milwaukee Lines: 42 In article <835@eutrc3.urc.tue.nl> p.v.bemmelen writes: |the user should be able to press multiple keys, and the program should |detect all of them, not just the last one pressed. To have this work properly, the main loop of your program needs to be a keyboard scanning routine. This can be done very easily in Turbo Pascal, accomplished with a routine such as: FUNCTION InKey : CHAR; BEGIN Port[$60] := $00; { set "no delay" repeat } WHILE NOT (KeyPressed) DO ; InKey := ReadKey END; This is all you need. Repeats will be handled as expected: upon they next call, they are still in the buffer, and will be able to read immediately read from this function. A few things to note: setting the repeat delay above may not work on XT class machines. I don't have access to an XT, but I have seen this used in one of Borland's OOP demonstration programs included with version 5.5 of TP. You'll have to experiment to determine if this is a portable usage. It makes no real difference to the program, but a faster repeat is indispensable, in my opinion. Note too that ReadKey returns zero if an extended key has been pressed. If you're using InKey as an expression in the case, check for zero and read the buffer again, i.e.: ch := InKey; CASE ch OF 0: ch := ReadKey; { get extended key } ... ... END; Keyboard reading is easily accomplished using Turbo's own built in function and really does not require any external interference unless you are preforming actions based upon control keys being pressed (i.e. if ALT is touched, the status line may display another set of functions, etc, etc.) -- D. Chadwick Gibbons (chad@csd4.csd.uwm.edu)