🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #1589

Re: Reading multiple keypresses at once

#1589
From: Markus Fischer
Date: Mon, 16 Jul 1990 11:14
51 lines
2918 bytes
In article <11396@hydra.gatech.EDU>, ccastje@prism.gatech.EDU (John Adair) writes:
> How do programs read multiple keys pressed at the same time (not just
> Alt and 'X')?  Many multiple player games allow two players to share
> the keyboard.  Is there a way to get the 8042 to alternate scan codes
> between the two keys (i doubt it)?  Do I have to sit there and poll
> the keyboard port (0x60, I think), remembering that the first key has
> sent a 'make', but not a 'break', before the second key sends a 'make'?
> Is there a simpler way to do this?
> 
> Along the same lines, how do I discard the keypresses before (or as soon
> as) they reach the buffer, preferably without having to constantly 
> read in and discard characters?

For what it's worth:  In the interrupt list (some outdated version, you can
find the latest at SIMTEL20 PD1:<MSDOS.INFO>INTER###.ZIP) I find:

INT 15 - OS HOOK - KEYBOARD INTERCEPT (AT model 3x9,Xt2,XT286,CONV,PS)
	AH = 4Fh
	AL = scan code
	CF set
Return: CF set
	    AL = scan code
	CF clear
	    scan code should not be used
Note: Called by INT 9 handler to translate scan codes

In an older posting, Tom Almy (at the time <toam@tekgvs.labs.tek.com>) used
this interrupt to remap the AT keyboard's CapsLock to another Ctrl key.  It
works beautifully.

A solution to your problem would thus be to write your own interrupt handler
for int 15, which would simply check for the AH==4fh (leaving all other
functions to the original handler, of course), and then update a global
variable to reflect the ``key-pressed state'' according the the scan code,
and clear CF.  This way, nothing would even *get* to the keyboard buffer!
(For that matter, you couldn't even put the keyboard in Ctrl, let alone
Alt-Ctrl state, with means Ctrl-C and Ctrl-Alt-Del are trapped!).

Your main loop would simply read the global variable, and act accordingly (e.g.
`left-ctrl F': player A fires at B, *and* `right-ctrl J': player B fires at A
* Both player dead: Draw!   *** GAME OVER ***   Another duel? (y/n)? _ :-)
.. hm, better release int 15 before the `(y/n)?' ...

BTW: TC's User Guide gives an example of this kind of interrupt handling, for
which you don't need a single line of assembler.  Speaking of TC, your global
variable should be `volatile' (make shure the compiler won't skip even a single
``read'' of that variable!).

Hope this helps

Markus Fischer,    Dpt. of Anthropology, Geneva.
Technical Details
Message-ID: <204@sc2a.unige.ch>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!samsung!uunet!mcsun!cernvax!chx400!ugun2b!ugsc2a!fisher
References: <11396@hydra.gatech.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!samsung!uunet!mcsun!cernvax!chx400!ugun2b!ugsc2a!fisher
From: fisher@sc2a.unige.ch (Markus Fischer)
Newsgroups: comp.os.msdos.programmer
Subject: Re: Reading multiple keypresses at once
Summary: use INT 15h, function AH=4Fh
Message-ID: <204@sc2a.unige.ch>
Date: 16 Jul 90 11:14:55 GMT
References: <11396@hydra.gatech.EDU>
Organization: University of Geneva, Switzerland
Lines: 51