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 › Creating multiple key presses to do different thin
Page Index Toggle Pages: 1
Creating multiple key presses to do different thin (Read 445 times)
Creating multiple key presses to do different thin
Apr 20th, 2009, 3:06pm
 
Hi guys,

I'm trying to create something like this in theory:

if(keyPressed) {
    if(key == 'f' && key == 'a' && key == 's' && key == 't') {
         do something
    }

Basically I'm trying to make it so you have to hold down multiple keys to make an event happen. However, since the program can only detect one key at a time, I'm at a roadblock of how to actually pull this off. I'm not a great programmer, so I thought what I just typed above would work but it didn't. Anybody have any ideas on how to do this?
Re: Creating multiple key presses to do different thin
Reply #1 - Apr 20th, 2009, 3:32pm
 
check out this link in which is shown a handler for checking the status of multiple keys on processing:
http://processing.org/hacks/hacks:multiplekeys?s=multiple%20keys

usually processing can only recognize one key being pressed at a time, and not multiple keys pressed simultaneously. therefore the key variable only has one value at a time, even though more than one key may be pressed.
Re: Creating multiple key presses to do different thin
Reply #2 - Apr 20th, 2009, 6:42pm
 
Thanks for this post. I tried this code. It does print out the code to the output screen, but the if statement checking multiple key presses still isn't working. Any ideas on why this is?

I'm talking about this line of code:

if(checkKey("ctrl") && checkKey("s")) println("CTRL+S"){
   background(255);
}

When I tried to use it, it didn't display anything.
Re: Creating multiple key presses to do different thin
Reply #3 - Apr 21st, 2009, 10:40am
 
haven't tried it but looking at your code, i believe you should remove the println after the test condition:

if(checkKey...&& ...)
{
  background(255);
}

did you insert the checkKey function declaration in the right place?
Page Index Toggle Pages: 1