forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Detecting multiple button presses

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
omlette



Joined: 16 Mar 2005
Posts: 5

PostPosted: Sat Sep 30, 2006 5:11 am    Post subject: Detecting multiple button presses Reply with quote

What's the correct way to detect if a user is pressing more than one button? I've been using the following method, which only seems to work if one button is pressed:

Code:
sceCtrlPeekBufferPositive(&paddata, 1);
if(paddata.Buttons & PSP_CTRL_blah & PSP_CTRL_blah2)
{
...
}


Thanks
Back to top
View user's profile Send private message
Insert_witty_name



Joined: 10 May 2006
Posts: 376

PostPosted: Sat Sep 30, 2006 5:17 am    Post subject: Reply with quote

You have a couple of options, all really down to preference really. I use the following in one of my projects:

Code:
if (pad.Buttons & PSP_CTRL_UP && pad.Buttons & PSP_CTRL_TRIANGLE)
Back to top
View user's profile Send private message
omlette



Joined: 16 Mar 2005
Posts: 5

PostPosted: Sat Sep 30, 2006 5:22 am    Post subject: Reply with quote

Thank you :)
Back to top
View user's profile Send private message
Aion



Joined: 24 Jul 2006
Posts: 40
Location: Montreal

PostPosted: Sat Sep 30, 2006 1:15 pm    Post subject: Reply with quote

Code:
u32 uWantedKeys;
uWantedKeys = PSP_CTRL_UP | PSP_CTRL_TRIANGLE; //As many other as you want

if( (pad.Buttons & uWantedKeys)  == uWantedKeys )
   // Do whatever


Or
Code:
u32 uWantedKeys;
uWantedKeys = PSP_CTRL_UP;
uWantedKeys |= PSP_CTRL_TRIANGLE;
//... As many other as you want

if( (pad.Buttons & uWantedKeys)  == uWantedKeys )
   // Do whatever
Back to top
View user's profile Send private message
Dremth



Joined: 15 Jul 2005
Posts: 14
Location: Round Rock, TX

PostPosted: Mon Oct 30, 2006 5:09 am    Post subject: Reply with quote

Neither of those worked for me. I think it may have something to do with the: "u32". What is u32?

Aion wrote:
Code:
u32 uWantedKeys;
uWantedKeys = PSP_CTRL_UP | PSP_CTRL_TRIANGLE; //As many other as you want

if( (pad.Buttons & uWantedKeys)  == uWantedKeys )
   // Do whatever


Or
Code:
u32 uWantedKeys;
uWantedKeys = PSP_CTRL_UP;
uWantedKeys |= PSP_CTRL_TRIANGLE;
//... As many other as you want

if( (pad.Buttons & uWantedKeys)  == uWantedKeys )
   // Do whatever
Back to top
View user's profile Send private message
hlide



Joined: 10 Sep 2006
Posts: 750

PostPosted: Mon Oct 30, 2006 6:57 am    Post subject: Reply with quote

Code:

#define BOTH_UP_AND_TRIANGLE_PRESSED (PSP_CTRL_UP|PSP_CTRL_TRIANGLE)

if ((pad.Buttons & BOTH_UP_AND_TRIANGLE_PRESSED) == BOTH_UP_AND_TRIANGLE_PRESSED)
{
  // do whatever you want when both UP and TRIANGLE are pressed
}


Aion's examples are not bad, but to create a variable to keep a constant is not something I would expect for such trivial thing, especially if you don't use before or after u32 a "const" directive.

usually u32 is declared that way :
Code:

typedef unsigned int u32;
Back to top
View user's profile Send private message
Dremth



Joined: 15 Jul 2005
Posts: 14
Location: Round Rock, TX

PostPosted: Mon Oct 30, 2006 9:33 am    Post subject: Reply with quote

Ok. Thanks a bunch!
Back to top
View user's profile Send private message
Aion



Joined: 24 Jul 2006
Posts: 40
Location: Montreal

PostPosted: Mon Oct 30, 2006 1:48 pm    Post subject: Reply with quote

I wouldn't usually store it in a variable, but I wanted the code to be as clear as possible for the example.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group