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
keypress again. (Read 476 times)
keypress again.
Feb 23rd, 2010, 10:59pm
 
hi everybody. I've searched the whole website for my problem. I want to press button a,z and then a again. But it doesn't respond. And i need a sollution that it switches after for instance an half an hour to an another setting.

could someone help me?

Code:

import themidibus.*; //Import the library
PImage seq1;
PImage seq2;
int count = 1;
PImage imgToProcess;
int i = 1;

MidiBus myBus; // The MidiBus

// Array for controller keys
boolean[] keys = new boolean[2];
final int a = 0;
final int z = 1;


void setup() {
 for (int i = 0; i< 2; i++) {
   keys[i] = false;
 }

}

void draw() {
 if(keys[a] == true) {  //pics W/O delay
   i=i+1;
   background(0);
   seq1= loadImage("seq1"+i+".jpg");

   image(seq1, 150, 150,200,200);
   // delay(500);


   if (i>49){
i=1;
   }
 }
 if(keys[z] == true) {  //Move the left player down.
   i=i+1;
   background(0);
   seq1= loadImage("seq1"+i+".jpg");

   image(seq1, 150, 150,200,200);
   delay(500);


   if (i>49){
i=1;
   }
 }

}

}
void keyPressed() {

if(key == 'a') {
  keys[a] = true;
}  else if (keyCode == 'z') {
  keys[z]= true;
}  else if (keyCode == 'a') {
  keys[z]= true;
}
}


void keyReleased() {

if(key == 'a') {
  keys[a] = true;
} else if(key == 'z') {
  keys[z] = true;
}
   }





void processImage(PImage img, int i) {
 // <-- process the image
 save("myimage" + i + ".png");
}
Re: keypress again.
Reply #1 - Feb 23rd, 2010, 11:29pm
 
hey, check your keyPressed and keyReleased code.  You're setting the bools to 'true' in each.  And keyPressed uses keyCode, while keyReleased (correctly) uses key.
Re: keypress again.
Reply #2 - Feb 24th, 2010, 5:13am
 
hi, thank you for your help. I did keypressed and keyreleased both on true, because i want to keep it running.  After changing keycode to key i've still got the same problem. I accidently didn't change that.
Re: keypress again.
Reply #3 - Feb 24th, 2010, 5:36am
 
got it!
void keyReleased() {

if(key == 'z') {
     keys[a] = false;
  keys[z] = true;
} else if(key == 'a') {
   keys[z] = false;
  keys[a] = true;
}
   }


Thanks for the help.
Does anyone know a sollution for changing from a to z after a half an hour? Delay() is not an option ofcourse, maybe hour() by calculating the time passed?
Page Index Toggle Pages: 1