Re: A85: Key Trapping


[Prev][Next][Index][Thread]

Re: A85: Key Trapping




On Wed, 17 Dec 1997 17:59:06 -0500, you wrote:

>
>First off I made a routine for a game I'm writing that loops until a key
>is pressed.  The keys it traps are the arrow keys, 2nd, and Exit.  The
>problem is that whenever 2nd is pressed, it goes through the code so
>fast that you have to very very quickly tap the 2nd key to make it
>execute the 2nd routine only once.  I've tried setting up a delay at the
>end of the 2nd rountine but it seems to freeze whenever I do that.  I
>don't know much about them, but would using ports instead of GET_KEY
>help?  Any ideas?  Thanks in advance,
>
> - Jim
>

If you want the key only to be pressed once, the way that i have used
is something like this:

InputLoop:
 xor a
 out (1),a
 in a,(1)		;read the keyboard port

 push af
 bit 3,a		;UP pressed?
 call z,DoSomethingUp
 pop af

 push af
 ....
 ....
 pop af

 ld (LASTKEYPRESS),a	;save the last keypress
 jr InputLoop


;when this is called, you know that Up is currently being pressed by
;the user.  so, you return from the routine if Up was pressed last
;time through the loop and this time.
DoSomethingUp:
 ld a,(LASTKEYPRESS)
 bit 3,a
 ret z			;return if key pressed last time
 ....
 ....
 ret

i think this is something like what you are looking for.

-mike pearce
mgp4007@omega.uta.edu


References: