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 › Distinguish between "Up Arrow" and Ctrl-"Up Arrow"
Page Index Toggle Pages: 1
Distinguish between "Up Arrow" and Ctrl-"Up Arrow" (Read 499 times)
Distinguish between "Up Arrow" and Ctrl-"Up Arrow"
Feb 7th, 2010, 2:13pm
 
As a rank newcomer, I'm having trouble trying to use keyPressed (and keyReleased?) to distinguish between inputting "up arrow" (i.e. keyCode == 38) by itself, and ctrl-"up arrow" (i.e. keyCode ==17 and then 38).  Can sometime take pity on my and show me how, please?
Re: Distinguish between "Up Arrow" and Ctrl-"Up Arrow"
Reply #1 - Feb 7th, 2010, 2:32pm
 
Found that on the forum, but I failed to note down the author... Sad
Code:
boolean ctrlPressed;

void keyPressed() {
 // special key
 if (key == CODED) {
   if (keyCode == CONTROL) {
ctrlPressed = true;
   }
 }
 // regular key
 else {
   if (ctrlPressed) {
// CTRL + KEY
   }
   else {
// OTHER
   }
 }
}

void keyReleased() {
 if (key == CODED) {
   if (keyCode == CONTROL) {
ctrlPressed = false;
   }
 }
}
Page Index Toggle Pages: 1