# Input needs to on for defined time before action

**URL:** <https://forum.universal-robots.com/t/input-needs-to-on-for-defined-time-before-action/32516>\
**Category:** Technical Questions\
**Created:** [February 2, 2024, 4:38pm UTC](https://forum.universal-robots.com/t/input-needs-to-on-for-defined-time-before-action/32516 "2024-02-02T16:38:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrispocock](https://avatars.discourse-cdn.com/v4/letter/c/dc4da7/32.png) [@chrispocock](https://forum.universal-robots.com/u/chrispocock)\
**Post date:** [February 2, 2024, 4:38pm UTC](https://forum.universal-robots.com/t/input-needs-to-on-for-defined-time-before-action/32516/1 "2024-02-02T16:38:41Z")

</div>

Hi, I have found several ways to carry out an action if an input is on for a certain amount of time.  
I’m wondering if there is an easy way though, what methods do you use?  
Thanks.

---

<div class="post-metadata">

**Author:** ![eric.feldmann](https://avatars.discourse-cdn.com/v4/letter/e/94ad74/32.png) [@eric.feldmann](https://forum.universal-robots.com/u/eric.feldmann)\
**Post date:** [February 2, 2024, 7:24pm UTC](https://forum.universal-robots.com/t/input-needs-to-on-for-defined-time-before-action/32516/2 "2024-02-02T19:24:21Z")

</div>

In a thread:

```auto
if(input_is_pressed) {
    time_variable = time_variable + get_steptime()
    if(time_variable >= my_threshold) {
        do_something()
    }
} else {
    time_variable = 0
}

```

Probably something like that. You could leave the conditional processing somewhere else in the code as long as you define time\_variable for global use.

---

<div class="post-metadata">

**Author:** ![efn](https://avatars.discourse-cdn.com/v4/letter/e/35a633/32.png) [@efn](https://forum.universal-robots.com/u/efn)\
**Post date:** [February 5, 2024, 10:32am UTC](https://forum.universal-robots.com/t/input-needs-to-on-for-defined-time-before-action/32516/3 "2024-02-05T10:32:38Z")

</div>

I would do it like this, using UR commands. 🙂 Or placed in a thread like Eric. Depends on your application.  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/f/f1d95431d364ea4060664b6e7b7ee0745874cd1f.png)
