# Screenshot with CTRL + S

**URL:** https://discourse.processing.org/t/screenshot-with-ctrl-s/27203
**Category:** Coding Questions
**Created:** [January 19, 2021, 5:04pm UTC](https://discourse.processing.org/t/screenshot-with-ctrl-s/27203 "2021-01-19T17:04:14Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Lukerfull](https://avatars.discourse-cdn.com/v4/letter/l/6a8cbe/32.png) [@Lukerfull](https://discourse.processing.org/u/Lukerfull)
#### Post date: [January 19, 2021, 5:04pm UTC](https://discourse.processing.org/t/screenshot-with-ctrl-s/27203/1 "2021-01-19T17:04:14Z")

</div>

Hi, I’ve been struggling with this for a long time today. I’m trying to make screenshots with ctrl and s but it doesn’t work. Can anyone help me? Thanks.

This is what I tried:

```auto
boolean ctrlPressed;

void keyPressed() {
    if (key == BACKSPACE) // this is to restart the program
      setup();                         
    else {
      if (keyCode == CONTROL) {
       ctrlPressed = true; 
      }
      else {
        if (ctrlPressed && key == 's' || key == 'S')
          saveFrame("drawing-######.jpg");
      }
    }
}  

```

---

<div class="post-metadata">

### Author: ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)
#### Post date: [January 19, 2021, 5:17pm UTC](https://discourse.processing.org/t/screenshot-with-ctrl-s/27203/2 "2021-01-19T17:17:16Z")

</div>

here is my solution. You need to press ‘s’ within “allow” milliseconds from releasing ctrl key

```auto
boolean key1 = false, key2 = false;
int start = 0, allow = 300;
void setup() {}
void draw() {if(frameCount % 50 == 0) println(key1,key2,millis());}
void keyPressed() {
  if(keyCode == CONTROL) key1 = true;
  if(key == 's') key2 = true;
  if(key2 && millis() > start && millis() < start + allow) { println("take screenshot!"); }
}
void keyReleased() {
  if(keyCode == CONTROL) {key1 = false; start = millis();}
  if(key == 's') key2 = false;
}

```

I find allow 300 to be the best. You can obviously configure it to your liking

---

<div class="post-metadata">

### Author: ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)
#### Post date: [January 19, 2021, 5:19pm UTC](https://discourse.processing.org/t/screenshot-with-ctrl-s/27203/3 "2021-01-19T17:19:36Z")

</div>

The problem with your attempt is that keyPressed() function can only recognise 1 key at the time. I solved it by adding a delay between pressing the keys

Edit: seems I was wrong

---

<div class="post-metadata">

### Author: ![ErraticGenerator](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/erraticgenerator/32/11304_2.png) [@ErraticGenerator](https://discourse.processing.org/u/ErraticGenerator)
#### Post date: [January 19, 2021, 5:50pm UTC](https://discourse.processing.org/t/screenshot-with-ctrl-s/27203/4 "2021-01-19T17:50:07Z")

</div>

source: [Processing 1.0 - Processing Discourse - CONTROL + char commands.](https://processing.org/discourse/beta/num_1249757306.html)

```java
boolean ctrlPressed = false;

void setup() {
  size(400, 400);
}

void draw() {
  background(200);
}

void keyPressed() {
  if (key == CODED) {
    if (keyCode == CONTROL) {
      println("control");
      ctrlPressed = true;
    }
  } else {
    if (ctrlPressed && keyCode == 83) { // 83 is keyCode for "s"
      println("ctrl + s");
      save("test.png");
    }
  }
}

void keyReleased() {
  if (key == CODED) {
    if (keyCode == CONTROL) {
      ctrlPressed = false;
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![Lukerfull](https://avatars.discourse-cdn.com/v4/letter/l/6a8cbe/32.png) [@Lukerfull](https://discourse.processing.org/u/Lukerfull)
#### Post date: [January 19, 2021, 6:36pm UTC](https://discourse.processing.org/t/screenshot-with-ctrl-s/27203/5 "2021-01-19T18:36:17Z")

</div>

Well, actually my code was right. I just write 83 instead of ‘s’ and it worked. Thank you!
