Article View: comp.os.msdos.programmer
Article #68Re: Keyboard handlers
From: Scott Ramsay
Date: Sat, 31 Oct 1992 15:46
Date: Sat, 31 Oct 1992 15:46
55 lines
1996 bytes
1996 bytes
>Hello
>
>I am trying to write a keyboard handler that will allow me
>to know if any two keys are being pressed simultaneously.
>What are the ports that i should read? And how do i interpret
>the this?
>
>-Chris Busch
You can access the keyboard via port 0x60 ($60 for pascal people)
The port returns the scan code of the key pressed. If the hi-bit
is set, then the key was released.
Pascal example:
const
hibit = $80;
var
spacebar,esc : boolean;
scancode : byte;
.
.
.
scancode := port[$60];
if scancode=$34 { scan code for space = 57dec }
then spacebar := true
else
if scancode=$34+hibit
then spacebar := false;
if scancode=1
then esc := true
else
if scancode=1+hibit
then esc := false;
The above code will return TRUE for SPACEBAR,ESC while it is
pressed. As soon as either key is released, SPACEBAR,ESC will
be set to false.
I suggest to override the keyboard interrupt at $9 and place
the coding there so you don't miss any keystrokes.
Also for games, I don't call the old keyboard interrupt. I
don't overflow the key buffer. (I hate it when the keyboard beeps)
This method works great in games. I use it for shoot-em games
that need to know when multiple keys are pressed and released.
Send e-mail if you have any more questions.
Scott Ramsay
ramsays@access.digex.com
Technical Details
Message-ID:
<Bwzt5o.9FL@access.digex.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!digex.com!ramsaysReferences:
<1cg2a5INNuun@ub.d.umn.edu>Show Full Headers
Complete Article Headers
Newsgroups: comp.os.msdos.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!digex.com!ramsays From: ramsays@access.digex.com (Scott Ramsay) Subject: Re: Keyboard handlers Message-ID: <Bwzt5o.9FL@access.digex.com> Sender: usenet@access.digex.com Nntp-Posting-Host: access.digex.com Organization: Express Access Online Communications, Greenbelt, MD USA References: <1cg2a5INNuun@ub.d.umn.edu> Date: Sat, 31 Oct 1992 15:46:34 GMT Lines: 55