How to sequence or switch case automatically?

Hi Mister,
Thank you so much.
I have re-write your playback program and now it works with my animation. :kissing_heart:
I have a last option to ask you if it is easy for you, and it’s not in a hurry at all…
How to record and playback the datas x and y of the mouse?

I put the record and playback program below

The record one

PrintWriter output;

float coupling,   noiseLevel;

void setup() {
  size(200, 200);
  output = createWriter("data.txt");
  output.println("0:0:0");
  textSize(100);
}

void draw() {
    coupling = map ((float (mouseX)/width*1), 0, 1, -50, 50 );
    noiseLevel=  map ((float (mouseY)/width*1), 0, 1, 0, 3 );
   
 //  print ("coupling: "); print (coupling);  print (" noiseLevel: "); println (noiseLevel);
  background(0);
  text(key, 20, height - 20);
    text(keyCode, 80, height - 20);
}

void keyPressed() {
  if (key == '@') {
    output.flush();
    output.close();
    exit();
  } else {
    output.println(frameCount + ":" + (int)key + ":" + (int)keyCode);
  }
}

The playback one

String[] lines;
int index = 0, nextFrame = 0; // these stay the same
char theKey; 
int theKeyCode;
float coupling;
float noiseLevel;

void setup() {
  size(200, 200);
  lines = loadStrings("data.txt");
  readOneLine();
  textSize(20);
 
}
void draw() {
//  theKeyCode = 'D'; keyPressed ( );
  background(0);
   coupling = map ((float (mouseX)/width*1), 0, 1, -50, 50 );
   noiseLevel=  map ((float (mouseY)/width*1), 0, 1, 0, 3 );
   
 //  print ("coupling: "); print (coupling);  print (" noiseLevel: "); println (noiseLevel);
  text(key, 20, height - 20);
  text(keyCode, 20, height - 40);
  if (frameCount == nextFrame) {
    readOneLine();
    keyPressed ( );
    key = 'D'; 
      keyPressed ( );
  }
  

//   keyPressed (theKey );
}

void readOneLine() {
  String[] current = split(lines[index], ':');
   key = (char)int(current[1]);
   keyCode = int(current[2]);
  if (++index == lines.length - 1) {
    exit();
  }
  nextFrame = int(split(lines[index], ':')[0]);
}

void keyPressed (  )  {// theKeyCode 
  
  if (keyCode == DOWN) {
    println("DOWN= DECREASE SPEED "); // 
  } 
  
  if (keyCode == UP) { 
    println("UP= INCREASZe SPEED "); // 
  }
  
    if (keyCode == '1'  ) {
      println(" 1111111 "); 
   }    
   
    if (keyCode == '2'  ) {
      println(" 2222222 "); 
   }    
   
   if (key  == 'é'  ) {
      println(" ééééééé "); 
      
   }    
     if (key =='D') {
      println(" Do Nothing ");  
      
        
 }
  if (key  =='&') {
      println(" &&&&& ");  
 }
 if (key   =='i') {
      println("iiiiiiiiiiiiiii ");  
 }
 
 
  if (key    =='I') {
      println("IIIIIIIIIIIII ");  
 }
 
 


 }
 

Hi :slight_smile:

I’ll take a look when I have more time. In the end your simple question has evolved into something that could be a library for recording and playing back all mouse and keyboard interactions :slight_smile:

Maybe someone wants to give it a try and create such a library? I think it should record all key pressed, released, mouse moved, pressed, released, mouse buttons, etc.

1 Like

You totally right , I will answer for someone to create this library in a new post. Thanks Mister.