# Trigger screenshot/export automatically?

**URL:** <https://openrndr.discourse.group/t/trigger-screenshot-export-automatically/73>\
**Category:** How to?\
**Created:** [April 5, 2020, 2:50pm UTC](https://openrndr.discourse.group/t/trigger-screenshot-export-automatically/73 "2020-04-05T14:50:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ferdinandsorg](https://yyz2.discourse-cdn.com/free1/user_avatar/openrndr.discourse.group/ferdinandsorg/32/57_2.png) [@ferdinandsorg](https://openrndr.discourse.group/u/ferdinandsorg)\
**Post date:** [April 5, 2020, 2:50pm UTC](https://openrndr.discourse.group/t/trigger-screenshot-export-automatically/73/1 "2020-04-05T14:50:08Z")

</div>

Knows everyone a way how to export or trigger the screenshot function automatically? As far as I know there is just the way with pressing the spacebar. Is there a way to hack this?

---

<div class="post-metadata">

**Author:** ![edwin](https://avatars.discourse-cdn.com/v4/letter/e/73ab20/32.png) [@edwin](https://openrndr.discourse.group/u/edwin)\
**Post date:** [April 5, 2020, 4:00pm UTC](https://openrndr.discourse.group/t/trigger-screenshot-export-automatically/73/2 "2020-04-05T16:00:37Z")

</div>

Hi Ferdinand! Welcome!

There is currently not a clean way to do it (I will keep it in mind for the next release). However, what you can do is the following to fake key presses.

```auto
fun main() {
    application {
        program {
            extend(Screenshots())
            extend {
                keyboard.keyDown.trigger(KeyEvent(KeyEventType.KEY_DOWN, ' '.toInt(), "space", emptySet()))
            }
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![ferdinandsorg](https://yyz2.discourse-cdn.com/free1/user_avatar/openrndr.discourse.group/ferdinandsorg/32/57_2.png) [@ferdinandsorg](https://openrndr.discourse.group/u/ferdinandsorg)\
**Post date:** [April 5, 2020, 8:10pm UTC](https://openrndr.discourse.group/t/trigger-screenshot-export-automatically/73/3 "2020-04-05T20:10:58Z")

</div>

Hey Edwin!  
That’s perfect working, thanks.

This could may a stupid question but how can I set an precise interval every 2 seconds only one screenshot.

I tried this, but its nur accurate enough:

> fun main() = application {  
> program {  
> extend(Screenshots())  
> extend {  
> val timer = seconds%2
> 
> ```
> if (timer < 0.02) {
> keyboard.keyDown.trigger(KeyEvent(KeyEventType.KEY_DOWN, ' '.toInt(), "space", emptySet()))
> }
> }
> }
> 
> ```
> 
> }

As well as a map function including sin(seconds). Its also not accurate enough.

Thanks Edwin.

---

<div class="post-metadata">

**Author:** ![edwin](https://avatars.discourse-cdn.com/v4/letter/e/73ab20/32.png) [@edwin](https://openrndr.discourse.group/u/edwin)\
**Post date:** [April 5, 2020, 8:18pm UTC](https://openrndr.discourse.group/t/trigger-screenshot-export-automatically/73/4 "2020-04-05T20:18:23Z")

</div>

To achieve as close as possible interval screenshots you would introduce a timestamp (`lastTime` in my example), you check against the timestamp and reset it when enough time has passed.

```auto
fun main() = application {
        program {
            extend(Screenshots())
            var lastTime = seconds
            extend {
                if (seconds - lastTime > 2.0) {
                    keyboard.keyDown.trigger(KeyEvent(KeyEventType.KEY_DOWN, ' '.toInt(), "space", emptySet()))
                    lastTime = seconds
                }
            }
        }
    }

```

---

<div class="post-metadata">

**Author:** ![ferdinandsorg](https://yyz2.discourse-cdn.com/free1/user_avatar/openrndr.discourse.group/ferdinandsorg/32/57_2.png) [@ferdinandsorg](https://openrndr.discourse.group/u/ferdinandsorg)\
**Post date:** [April 5, 2020, 8:23pm UTC](https://openrndr.discourse.group/t/trigger-screenshot-export-automatically/73/5 "2020-04-05T20:23:00Z")

</div>

This is exactly what I need, thank you!
