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
Button Controls? (Read 440 times)
Button Controls?
Feb 23rd, 2006, 9:21pm
 
is it possible to have proccesing recive input from 2 keys on the keyboard at the same time?

im in the middle of creating a 3D game for a 4th year project. i have the model (Enterprise E) moving around nicely but you can only move it one direction at a time. and if you fire a weapon and try to turn at the same time it wont work either!

Any help would be very much appriciated

Graham!
Re: Button Controls?
Reply #1 - Feb 24th, 2006, 9:13am
 
Something i whipped up

Code:

boolean[] keys = new boolean[526];
boolean checkKey(String k)
{
for(int i = 0; i < keys.length; i++)
if(KeyEvent.getKeyText(i).toLowerCase().equals(k.toLowerCase())) return keys[i];
return false;
}

void keyPressed()
{
keys[keyCode] = true;
}

void keyReleased()
{
keys[keyCode] = false;
}



Usage:
 if(checkKey("s") && checkKey("ctrl")) ellipse(width/2,height/2,40,40);  


-seltar
Page Index Toggle Pages: 1