# keyReleased()+ saveFrame() functions not doing anything

**URL:** https://discourse.processing.org/t/keyreleased-saveframe-functions-not-doing-anything/40832
**Category:** Coding Questions
**Created:** [February 5, 2023, 1:05am UTC](https://discourse.processing.org/t/keyreleased-saveframe-functions-not-doing-anything/40832 "2023-02-05T01:05:19Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![liss](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@liss](https://discourse.processing.org/u/liss)
#### Post date: [February 5, 2023, 1:05am UTC](https://discourse.processing.org/t/keyreleased-saveframe-functions-not-doing-anything/40832/1 "2023-02-05T01:05:19Z")

</div>

Hi all, I’m an _extreme novice_ coder taking a generative art course.

I am trying to save the image I created with a series of for loops and random functions (I included one in the script below) but it is not saving the image in the Processing\>\>document folder at all, or anywhere from what I can tell.

```auto
int alpha = 10;``
void setup() {
  size (1280, 548);
  background(205, 198, 188);
  noFill();
  
   for (int i = 0; i < 40; i++) {
    if (i < 30 && i > 15) {
      stroke(150, 144, 132, alpha);
    } else {
      stroke (150, 144, 132);
    }

    quad(994 + random(-20, 20),
      415 + random(-20, 20),
      1108 + random(-20, 20),
      415 + random(-20, 20),
      1108 + random(-20, 20),
      520 + random(-20, 20),
      994 + random(-20, 20),
      520 + random(-20, 20));
  }
}

void keyReleased() {
  if (key == 's') {
    saveFrame();
  }
}

```

If you run it and it does create an image or if you see any egregious errors in the keyReleased() or saveFrame() syntax please let me know!

---

<div class="post-metadata">

### Author: ![liss](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@liss](https://discourse.processing.org/u/liss)
#### Post date: [February 5, 2023, 2:02am UTC](https://discourse.processing.org/t/keyreleased-saveframe-functions-not-doing-anything/40832/2 "2023-02-05T02:02:54Z")

</div>

Update:  
I was able to fix it by not using the keyReleased() function and just doing a saveFrame() instead within setup().

```auto
int alpha = 10;

void setup() {
  size (1280, 548);
  background(205, 198, 188);
  noFill();

for (int i = 0; i < 40; i++) {
    if (i < 30 && i > 15) {
      stroke(150, 144, 132, alpha);
    } else {
      stroke (150, 144, 132);
    }

    quad(994 + random(-20, 20),
      415 + random(-20, 20),
      1108 + random(-20, 20),
      415 + random(-20, 20),
      1108 + random(-20, 20),
      520 + random(-20, 20),
      994 + random(-20, 20),
      520 + random(-20, 20));
  }
  saveFrame("sketch-######.png");
}

```

I hope this helps anyone else having the same issue.

---

<div class="post-metadata">

### Author: ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)
#### Post date: [February 5, 2023, 2:09am UTC](https://discourse.processing.org/t/keyreleased-saveframe-functions-not-doing-anything/40832/3 "2023-02-05T02:09:27Z")

</div>

Hi and welcome

Good place to start

> **[Welcome to Processing!](https://processing.org/)**
>
> Processing is a flexible software sketchbook and a language for learning how to code. Since 2001, Processing has promoted software literacy within the visual arts and visual literacy within technology…

> **[saveFrame() / Reference](https://processing.org/reference/saveframe_)**
>
> Saves a numbered sequence of images, one image each time the function is run. To save an image that is identical to the display window, run the function at the end of draw() or within mouse and…

https://www.youtube.com/embed/2VLaIr5Ckbs?feature=oembed&wmode=opaque&list=PLzJbM9-DyOZyMZzVda3HaWviHqfPiYN7e

---

<div class="post-metadata">

### Author: ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)
#### Post date: [February 6, 2023, 12:51am UTC](https://discourse.processing.org/t/keyreleased-saveframe-functions-not-doing-anything/40832/4 "2023-02-06T00:51:15Z")

</div>

Hi

```auto
void keyPressed()
{
  if(key=='s') saveFrame("any.png");
}

```

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [February 6, 2023, 1:15am UTC](https://discourse.processing.org/t/keyreleased-saveframe-functions-not-doing-anything/40832/5 "2023-02-06T01:15:53Z")

</div>

I think that you need a draw() function to make keyPressed and keyReleased etc. work
