gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Interrupt on KeyUp ?

#7674 - Pokemonster - Sun Jun 22, 2003 9:18 pm

Hi!

I'm currently trying out different types of getting keypad input. I'm using interrupts at the moment. The problem is, an interrupt is fired only once when a key is pressed. For continued key pressing, I need a way to figure out if the key has been released. Is there a way to do this ?

ALex

#7687 - Sweex - Sun Jun 22, 2003 11:57 pm

The button register is inverted... So if a certain bit indicates 1, it means that it is NOT pressed.

Dunno how this works with interrupts, but what I'd do is copy the button register into a variable each frame and use the variable. As a bonus, you will not have issues when a button is released during a frame. (Imagine checking the register itself and in on part of your code a button is pressed, but in another it isn't anymore...

#7690 - tepples - Mon Jun 23, 2003 12:05 am

Pokemonster wrote:
I'm currently trying out different types of getting keypad input. I'm using interrupts at the moment. The problem is, an interrupt is fired only once when a key is pressed.

That's strange; I get somewhere around three to ten rapid-fire interrupts on each keypress because the switches are quite bouncy.

Quote:
For continued key pressing, I need a way to figure out if the key has been released. Is there a way to do this ?

Most games seem to get their input by polling. In your main game loop, poll the joypad register until it shows that the button has been released.

I find the joypad interrupts useful for two things: 1. in joyirqmode=ANY, receiving key-down events at more than 1/60 second precision (useful in Street Fighter style fighting games, but polling at y=0, 80, 160 produces nearly the same effect) and 2. in joyirqmode=ALL, waking from sleep mode.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.