# How to sequence or switch case automatically?

**URL:** https://discourse.processing.org/t/how-to-sequence-or-switch-case-automatically/17464
**Category:** Electronics (Arduino, etc.)
**Created:** [January 30, 2020, 6:27pm UTC](https://discourse.processing.org/t/how-to-sequence-or-switch-case-automatically/17464 "2020-01-30T18:27:35Z")
**Posts on this page:** 3
**Page:** 2

<div class="post-metadata">

### Author: ![bking](https://avatars.discourse-cdn.com/v4/letter/b/dc4da7/32.png) [@bking](https://discourse.processing.org/u/bking)
#### Post date: [August 17, 2020, 3:52pm UTC](https://discourse.processing.org/t/how-to-sequence-or-switch-case-automatically/17464/21 "2020-08-17T15:52:35Z")

</div>

Hi Mister,  
Thank you so much.  
I have re-write your playback program and now it works with my animation. 😘  
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

```auto
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

```auto
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 ");  
 }
 
 

 }
 

```

---

<div class="post-metadata">

### Author: ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)
#### Post date: [August 18, 2020, 9:54am UTC](https://discourse.processing.org/t/how-to-sequence-or-switch-case-automatically/17464/22 "2020-08-18T09:54:34Z")

</div>

Hi 🙂

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 🙂

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.

---

<div class="post-metadata">

### Author: ![bking](https://avatars.discourse-cdn.com/v4/letter/b/dc4da7/32.png) [@bking](https://discourse.processing.org/u/bking)
#### Post date: [September 1, 2020, 7:31am UTC](https://discourse.processing.org/t/how-to-sequence-or-switch-case-automatically/17464/23 "2020-09-01T07:31:28Z")

</div>

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

[Previous page](https://discourse.processing.org/t/how-to-sequence-or-switch-case-automatically/17464.md?page=1)
