Key Press
Posted: Tue Aug 23, 2011 11:46 pm
Hello
I have tried to create my own function for key presses where it will detect only once if a key has been pressed and released. All seems fine with it however when i try to get it to work with more than one key it fails. It will only work if the same key that was last pressed is pressed again before another key can used. I'm still a newbie with PB so forgive my mistakes
What happens is when i press enter it pauses which is should do but when i press right i can only do it once before i have to press enter again to 'release' the key so i can press right again. Is there some way around this? Throughout searching i only saw that people use key releases to execute actions but not key presses. ExamineKeyboard() is in the game loop above the key pressing, if needed i can post more code.
I have tried to create my own function for key presses where it will detect only once if a key has been pressed and released. All seems fine with it however when i try to get it to work with more than one key it fails. It will only work if the same key that was last pressed is pressed again before another key can used. I'm still a newbie with PB so forgive my mistakes

Code: Select all
Global press=1
Procedure KeyboardPressed(KeyID)
If press=1
If KeyboardPushed(KeyID)
press=0
ProcedureReturn 1
EndIf
ElseIf press=0 And KeyboardReleased(KeyID)
press=1
EndIf
EndProcedure
If Camera\move=0
If Inventory\pause=0
If KeyboardPressed(#PB_Key_Return)
Inventory\pause=1
EndIf
ElseIf Inventory\pause=1
If KeyboardPressed(#PB_Key_Return)
Inventory\pause=0
EndIf
EndIf
If Inventory\pause=1
DisplaySprite(#Inventory,0,16)
DisplayTransparentSprite(#Selector,Inventory\x,Inventory\y)
If KeyboardPressed(#PB_Key_Right)
Inventory\x+32
EndIf
EndIf
EndIf