Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Reading the keyboard

1 view
Skip to first unread message

p.v.bemmelen

unread,
Aug 12, 1989, 2:08:07 PM8/12/89
to

Hello
I am writing a program (in fact a game) that needs to read the keyboard.
Of course the standard method is not good enough because it has a delay
before the key starts repeating, and if you press multiple keys the result
is incorrect.
What i need is the following:
the user should be able to press multiple keys, and the program should
detect all of them, not just the last one pressed.
The program should read which keys are pressed at that moment, not which
have been pressed lately

I believe this requires programming of the keyboard controller, or reading portsdirectly. The language is Turbo Pascal 4,5 of 5.5, but examples in C or assembler are also welcome. Using the intr() function is no problem.

Greetings
wsi...@eutrc3.UUCP

D. Chadwick Gibbons

unread,
Aug 22, 1989, 11:28:40 PM8/22/89
to
In article <8...@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 (ch...@csd4.csd.uwm.edu)

0 new messages