We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Multiple Keys (Read 2901 times)
Multiple Keys
May 27th, 2008, 1:36am
 
Hey,
I'm actually using the JS version of Processing, but I ran into a problem with multiple keys being pressed. I tried the boolean array keeping track of what has been pressed etc (I'm making a block move around).  The problem occurs here:

keypress 1 -> keypress 2 -> keyrelease 2 -> keyrelease 1

In my array, the release of key 1 isn't updated (presumably because the key variable is only for key 2?)

Any advice would be helpful.  Thanks!
Re: Multiple Keys
Reply #1 - May 27th, 2008, 9:40am
 
That sounds like it could be a bug in the JS version of processing. In the real version storing presses/releases per key works fine, e.g.

Code:
boolean keyUp,keyDown; //etc

void draw()
{
if(keyUp)
//do something...
if(keyDown)
//do something..
//etc etc
}

void keyPressed()
{
if(key==UP)
keyUp=true;
else if(key==DOWN)
keyDown=true;
}

void keyReleased()
{
if(key==UP)
keyUp=false;
else if(key==DOWN)
keyDown=false;
}
Page Index Toggle Pages: 1