r/processing • u/ComfortableMachine4 • May 14 '21
Hi guys need HELP!!!!!
Hi can anyone tell me how to have two separate key pressed events in your code in processing.
Currently I have 2 seperate keypressed events.
I want the 2 keyPressed events to occur 1 at a time.
But at the moment they occur at the same time when a key is pressed.
3
u/i-live-life May 14 '21
In your code you are looking at the keyPressed event in one if statement and then again seperately in other. Since the key has been pressed, both of these events become true and both sets of code are executed.
The reference documentation has an example that uses keyCode so that you can do different things depending on the actual key pressed, see here: https://processing.org/reference/keyCode.html
1
u/x-seronis-x May 14 '21 edited May 14 '21
First fix your terminology. You're not using the keyPressed event at all. You're using the state variable.
https://processing.org/reference/keyPressed_.html
The keyPressed() event (if you start using it) will be called exactly once per key being pressed. Its not called 'at exact same time'. But you can set whatever state you want during those events and react to them at the same time in your draw() event. This allows you to handle different actions based on different keys.
You can always choose to keep NOT using the keyPressed event and only examine the keyPressed state variable like you are currently doing. And if you want to do multiple things then just DO MULTIPLE THINGS. You can put as many lines of code as you want in whatever conditional block checks the state
4
u/mflouze Seeker of Knowledge May 14 '21
Hi ! It would be easier to help you if you showed us your code.