On/off with keypressed and released

Hi,

the following bit of my script I would like to activate only when a key is pressed and hold. I would like to deactivate it as soon as the key is released. How can I do this?

Thanks,

// (it is located at the end of void draw section)
float[][] temp = previous;//ripple. if disables, only creates static pixels
        previous = current;
        current = temp;
if(keyPressed) {


}

You could try something similar to the following two examples. :slight_smile:

 if (keyPressed && (key == 'a' || key == 'A')) {
    float[][] temp = previous;
    previous = current;
    current = temp;
 }
if (keyPressed && (key == CODED) && (keyCode == LEFT)) {
   float[][] temp = previous;
   previous = current;
   current = temp;
 }

Edit: Sorry I just realised this is an old thread from over 8 months ago.

2 Likes