QJ.NET | Videos | Forums | iPhone | MMORPG | Nintendo DS | Wii | PlayStation 3 | PSP | Xbox 360 | PC | Downloads | Contact Us
Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact

QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides

Go Back   QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides > Developers Corner > PSP Development, Hacks, and Homebrew > PSP Development Forum
The above video goes away if you are a member and logged in, so log in now!

key handling

This is a discussion on key handling within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; so because, from what i've seen from the tutorials on this site, all psp programs have to be looped, this ...

Reply
 
LinkBack Thread Tools
Old 07-24-2006, 01:27 PM   #1
 
Join Date: Dec 2005
Location: Toronto, Canada
Posts: 26
Trader Feedback: 0
Default key handling

so because, from what i've seen from the tutorials on this site, all psp programs have to be looped, this causes some problems with key handling.
for example, lets say i have some code, where hitting x increments the value of something variable by 1.

Code:
char str[10];
int variable=0;

while(1)
{
    sprintf(str, "%d", variable);
    printTextScreen(3, 3, str, RGB(255, 255, 255));

    sceCtrlReadBufferPositive(&pad, 1);
        if(pad.Buttons & PSP_CTRL_CROSS) {
           variable++;
        }
        flipScreen()
}
something along those lines.
because the program is constantly looped, hitting cross once will increment the value of variable by say...4, depending on how long it takes you to press down cross and release.

how can i prevent this from happening?
karmon is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 07-24-2006, 01:29 PM   #2

 
Zettablade's Avatar
 
Join Date: May 2006
Location: Programming or Farming Mudkips
Posts: 657
Trader Feedback: 0
Default

Quote:
Originally Posted by karmon
so because, from what i've seen from the tutorials on this site, all psp programs have to be looped, this causes some problems with key handling.
for example, lets say i have some code, where hitting x increments the value of something variable by 1.

Code:
char str[10];
int variable=0;

while(1)
{
    sprintf(str, "%d", variable);
    printTextScreen(3, 3, str, RGB(255, 255, 255));

    sceCtrlReadBufferPositive(&pad, 1);
        if(pad.Buttons & PSP_CTRL_CROSS) {
           variable++;
        }
        flipScreen()
}
something along those lines.
because the program is constantly looped, hitting cross once will increment the value of variable by say...4, depending on how long it takes you to press down cross and release.

how can i prevent this from happening?
doing that whole oldpad thingy.
__________________
Current Project: Citrus
Zettablade is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 07-24-2006, 01:29 PM   #3
 
Join Date: Dec 2005
Location: Toronto, Canada
Posts: 26
Trader Feedback: 0
Default

hmmm...do you think you could explain that?
karmon is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 07-24-2006, 01:31 PM   #4

total-Z
 
youresam's Avatar
 
Join Date: Jul 2005
Location: texas
Posts: 2,803
Trader Feedback: 0
Default

You save the pad varaible to another variable (such as oldpad), then you say if pad and NOT oldpad (forgot the C syntax )
__________________
牧来栠摩琠敨映汩獥
PSN: youresam
From Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth
youresam is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 07-24-2006, 01:33 PM   #5
 
Join Date: Dec 2005
Location: Toronto, Canada
Posts: 26
Trader Feedback: 0
Default

i'm sorry, i'm really new to programming for the psp, as you can probably see, is there any way i could get an exmaple of how this is done?
karmon is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 07-24-2006, 01:35 PM   #6

 
Zettablade's Avatar
 
Join Date: May 2006
Location: Programming or Farming Mudkips
Posts: 657
Trader Feedback: 0
Default

Sure.

Code:
char str[10];
int variable=0;

while(1)
{
unsigned int paddata_old = 0;
SceCtrlData paddata;
    sprintf(str, "%d", variable);
    printTextScreen(3, 3, str, RGB(255, 255, 255));

    sceCtrlReadBufferPositive(&pad, 1);
if(paddata.Buttons != paddata_old){
if(paddata.Buttons & PSP_CTRL_CROSS) variable++;
}
        flipScreen()
}
__________________
Current Project: Citrus
Zettablade is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 07-24-2006, 07:42 PM   #7
 
Join Date: Dec 2005
Location: Toronto, Canada
Posts: 26
Trader Feedback: 0
Default

sweet, thanks a lot.

nevermind, i got it to work.

Last edited by karmon; 07-24-2006 at 08:12 PM..
karmon is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 07-25-2006, 02:51 AM   #8
Art

Bush Programmer
 
Art's Avatar
 
Join Date: Nov 2005
Posts: 3,557
Trader Feedback: 0
Default

Or you could use a button debounce routine so the program doesn't even look at the buttons again for X amount of time.
Some programs might require use of the same button twice in a row.
Art is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 07-25-2006, 04:40 AM   #9

Cool Developer
 
Sturmeh's Avatar
 
Join Date: Nov 2005
Location: Australia
Posts: 1,301
Trader Feedback: 0
Default

The best way is to make it set a value to one everytime a key is pressed, and dont allow checking for key until the key has been released, which will declare the same variable as 0 again, which will allow the key to be input again.

But listen to these guys, my idea's prolly oldschool.
__________________
Hmm...
Sturmeh is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
handling , key

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -8. The time now is 03:35 AM.



Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © 2009, QJ.NET. All Rights Reserved.
Contact Us