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.
IndexProgramming Questions & HelpSyntax Questions › simultaneous keyCode inputs
Page Index Toggle Pages: 1
simultaneous keyCode inputs (Read 688 times)
simultaneous keyCode inputs
Apr 14th, 2008, 5:36am
 
This seems like a simple question -
Is it possible to specify multiple, simultaneous 'keyCode' key presses, for example, "SHIFT + UP"?

Was thinking something like...    

if ((keyCode == SHIFT) && (keyCode == UP)){

...but that doesn't seem to work.

Re: simultaneous keyCode inputs
Reply #1 - Apr 14th, 2008, 10:56am
 
Unfortunately only one key is registered at any time, if you want to keep track of multiple presses, you have to store what's been pressed, and if it's been released to give a list of currently pressed keys.
Re: simultaneous keyCode inputs
Reply #2 - Apr 14th, 2008, 11:47am
 
JohnG is right, but there is a trick to simulate several Keys Pressed.
(cascading statements)

Code:

void keyPressed() {
if (keyCode == SHIFT){
if (keyCode == UP){
...
your code here
...
}
}
}
Re: simultaneous keyCode inputs
Reply #3 - Apr 15th, 2008, 5:22am
 
Thanks John and jay; I had actually tried that cascading trick, to no avail...

Re: simultaneous keyCode inputs
Reply #4 - Apr 15th, 2008, 3:03pm
 
for more advanced control of key input, you can use the keyEvent object, which gets you into how Java handles events. so in this case, use keyEvent.isShiftDown() after checking the keyCode to see if it's "UP".

Code:

void draw() {
}

void keyPressed() {
if (keyCode == UP) {
println("up");
if (keyEvent.isShiftDown()) {
println("..and shift");
}
}
}
Re: simultaneous keyCode inputs
Reply #5 - Apr 16th, 2008, 4:58am
 
Beautiful - thanks fry
Re: simultaneous keyCode inputs
Reply #6 - Apr 16th, 2008, 8:08am
 
Well this is a go yo, real, peace.
Page Index Toggle Pages: 1