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.

Beginners > how do you check for key presses between loops.

#21997 - tornadokick - Fri Jun 11, 2004 12:01 am

One popular (as it's discussed) way to avoid having a key called is to check the keypad registers every x cycles of the main while loop. What is recommended to avoid missing presses between getInput calls...

#21999 - Miked0801 - Fri Jun 11, 2004 12:13 am

If you are truely worried about picking up input more than 60 times (or 30) a second, then you could use the joypad interrupt, but we've never needed to do that here for anything save sleep mode. Just polling regularly works great.

#22000 - tornadokick - Fri Jun 11, 2004 1:45 am

Miked0801 wrote:
If you are truely worried about picking up input more than 60 times (or 30) a second, then you could use the joypad interrupt, but we've never needed to do that here for anything save sleep mode. Just polling regularly works great.


I'm sorry if my first post was a bit confusing. For the input of the game, I had a value increment every iteration. Every 7th (or whatever) iteration, I run several commands, including my "getInput()" function. The problem that I'm having is that sometimes the user can press a key between the calls, which is both unpleasant and unprofessional (unprofessional because I'm leaving bugs in the output of my program). I tried implementing something earlier, but I scrapped it, b/c it didn't work.

#22001 - tepples - Fri Jun 11, 2004 2:15 am

Poll the controller every frame, and OR the readings together (or AND them together if you're working with the active-low raw data). This will catch a press and release that happens between frameskips.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.