| View previous topic :: View next topic |
| Author |
Message |
omlette
Joined: 16 Mar 2005 Posts: 5
|
Posted: Sat Sep 30, 2006 5:11 am Post subject: Detecting multiple button presses |
|
|
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 |
|
 |
Insert_witty_name
Joined: 10 May 2006 Posts: 376
|
Posted: Sat Sep 30, 2006 5:17 am Post subject: |
|
|
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 |
|
 |
omlette
Joined: 16 Mar 2005 Posts: 5
|
Posted: Sat Sep 30, 2006 5:22 am Post subject: |
|
|
| Thank you :) |
|
| Back to top |
|
 |
Aion
Joined: 24 Jul 2006 Posts: 40 Location: Montreal
|
Posted: Sat Sep 30, 2006 1:15 pm Post subject: |
|
|
| 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 |
|
 |
Dremth
Joined: 15 Jul 2005 Posts: 14 Location: Round Rock, TX
|
Posted: Mon Oct 30, 2006 5:09 am Post subject: |
|
|
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 |
|
 |
hlide
Joined: 10 Sep 2006 Posts: 750
|
Posted: Mon Oct 30, 2006 6:57 am Post subject: |
|
|
| 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 |
|
 |
Dremth
Joined: 15 Jul 2005 Posts: 14 Location: Round Rock, TX
|
Posted: Mon Oct 30, 2006 9:33 am Post subject: |
|
|
| Ok. Thanks a bunch! |
|
| Back to top |
|
 |
Aion
Joined: 24 Jul 2006 Posts: 40 Location: Montreal
|
Posted: Mon Oct 30, 2006 1:48 pm Post subject: |
|
|
| 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 |
|
 |
|