delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2004/02/29/04:04:50

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: Tim Nicholson <tim AT gizzy DOT dot DOT co DOT dot DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Handling multiple keys in video game
Date: Sun, 29 Feb 2004 08:37:27 +0000 (UTC)
Organization: BT Openworld
Lines: 38
Message-ID: <c1s8c6$k2b$1@sparta.btinternet.com>
References: <f9c129dc DOT 0402141419 DOT 5a3dc3e AT posting DOT google DOT com>
NNTP-Posting-Host: host81-128-153-22.in-addr.btopenworld.com
Mime-Version: 1.0
X-Trace: sparta.btinternet.com 1078043847 20555 81.128.153.22 (29 Feb 2004 08:37:27 GMT)
X-Complaints-To: news-complaints AT lists DOT btinternet DOT com
NNTP-Posting-Date: Sun, 29 Feb 2004 08:37:27 +0000 (UTC)
In-Reply-To: <f9c129dc.0402141419.5a3dc3e@posting.google.com>
X-Accept-Language: en-us, en
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6b) Gecko/20031210
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

Mike H wrote:
 > How do I tell which keys are being held down (W, A, S, and D for
 > example) either alone or simultaneously? If I try to use inportb(0x60)
 > and press A, then S, then release A, I get something like
 >
 > 30
 >
 > 31
 >
 > 158 for a split second
 > 31.
 >
 > This is bad if the game doesn't recognize that split second. What
 > technique do you use?

To do it yourself you would need to write an Interrupt service routine 
for the keyboard interrupt line IRQ01. Although this is not too 
difficult under DJGPP, it does involve a good understanding of both 
DJGPP and the PC hardware. A better solution would be to download the 
Allegro games programming library for DJGPP (and others) from 
http://www.talula.demon.co.uk/allegro/ this will give you all the 
keyboard control you need and a lot of additional useful games stuff as 
well.

Allegro provides you with a Boolean array called key[] which contains an 
entry for each key with a true value if the key is down and a false if 
it is up, this means that if you which to test if both A and S are 
pressed you just need a statement like

	if (key[KEY_A] && key[KEY_S])
		{
		..
		}

Hope this is some help


Tim Nicholson

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019