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 > button press question

#9779 - KoaM - Mon Aug 18, 2003 1:11 am

Hey all, KoaM the GBA n00b here again.
I have a question obviously.

I'm trying to detect keypresses.

Now I use the

if(!(*KEYS & KEY_B))

format to detect the presses which works fine when the person is holding down the button. Now suppose I want to make it so that if the person presses "B" for example, whatever is in the "if(!(*KEYS & KEY_B))" statement will only happen once, until the person releases the "B" button and presses it again, how would i go about this?

I guess my question for those of you familiar with VB terminology is how do i code ON_KEY_PRESS instead of ON_KEY_DOWN in C++.

#9782 - KoaM - Mon Aug 18, 2003 1:24 am

ah nevermind, me stupid.

#9785 - hnager - Mon Aug 18, 2003 4:01 am

Out of curiousity - what method did you use to solve it?

#9798 - col - Mon Aug 18, 2003 1:07 pm

I posted some code in this thread - look at the last few posts.
I think it will solve most button press/release issues.

http://forum.gbadev.org/viewtopic.php?t=1710

cheers

Col

#9877 - KoaM - Wed Aug 20, 2003 11:43 pm

Code:
if((a_flag) && !(*KEYS & KEY_A)) // Key pressed
{
changeBlast();
a_flag = FALSE;
}

if((*KEYS) & KEY_A)   a_flag = TRUE; // key released