# Mimic a Momentary Button via Scripting

**URL:** <https://forum.inductiveautomation.com/t/mimic-a-momentary-button-via-scripting/2093>\
**Category:** Ignition\
**Created:** [July 30, 2010, 6:45pm UTC](https://forum.inductiveautomation.com/t/mimic-a-momentary-button-via-scripting/2093 "2010-07-30T18:45:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![RRNut](https://avatars.discourse-cdn.com/v4/letter/r/8e7dd6/32.png) [@RRNut](https://forum.inductiveautomation.com/u/RRNut)\
**Post date:** [July 30, 2010, 6:45pm UTC](https://forum.inductiveautomation.com/t/mimic-a-momentary-button-via-scripting/2093/1 "2010-07-30T18:45:27Z")

</div>

Hopefully this isn’t too easy of a question. Alot of times in SCADA applications you need to send a “pulsed” command down to a device, hence the Momentary Button. Is there an easy way to do this via scripting? In other words, use either a transaction group or other event to send a pulsed command (say for 3 to 5 seconds) and then set the value back to zero.

Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![Robert.McKenzie](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/robert.mckenzie/32/4134_2.png) [@Robert.McKenzie](https://forum.inductiveautomation.com/u/Robert.McKenzie)\
**Post date:** [July 30, 2010, 8:41pm UTC](https://forum.inductiveautomation.com/t/mimic-a-momentary-button-via-scripting/2093/2 "2010-07-30T20:41:18Z")

</div>

You could use the GetVariable()/StorVariable functions in SQLBridge to count out a timer for you. ie make a group that runs every second with the following Expression item steps:

get: GetVariable()  
write: If(var \> 5, 0, 1) (writes back to the trigger opcitem)  
increment: If(var \> 5, 0, var+1)  
store: StoreVariable(increment)

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [August 5, 2010, 4:12pm UTC](https://forum.inductiveautomation.com/t/mimic-a-momentary-button-via-scripting/2093/3 "2010-08-05T16:12:35Z")

</div>

Did you really want to do this in a transaction group or in scripting? In scripting it could be as simple as:

`import time
system.tag.writeToTag("MyTags/TagX", 1)
time.sleep(5)
system.tag.writeToTag("MyTags/TagX", 0)`

---

<div class="post-metadata">

**Author:** ![DarrenAsh](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@DarrenAsh](https://forum.inductiveautomation.com/u/DarrenAsh)\
**Post date:** [August 9, 2010, 9:12pm UTC](https://forum.inductiveautomation.com/t/mimic-a-momentary-button-via-scripting/2093/4 "2010-08-09T21:12:53Z")

</div>

OK, slightly off topic question. If you have a script like this on a screen, does this block other scripts until that one is complete? Is the scripting engine threaded?

Sorry for the question if this is covered in the manual, but it just popped into my head while reading the thread.

Darren

---

<div class="post-metadata">

**Author:** ![Robert.McKenzie](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/robert.mckenzie/32/4134_2.png) [@Robert.McKenzie](https://forum.inductiveautomation.com/u/Robert.McKenzie)\
**Post date:** [August 11, 2010, 10:34pm UTC](https://forum.inductiveautomation.com/t/mimic-a-momentary-button-via-scripting/2093/5 "2010-08-11T22:34:33Z")

</div>

Unless you tell it otherwise, all client scripts use the GUI thread. That means they will block everything until it is complete (including interaction with the screens). Check out system.util.invokeAsynchronous() in the [help manual](http://www.inductiveautomation.com/support/usermanuals/ignition/) for more information.

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [August 13, 2010, 10:03pm UTC](https://forum.inductiveautomation.com/t/mimic-a-momentary-button-via-scripting/2093/6 "2010-08-13T22:03:32Z")

</div>

Right, to be clear, scripting is not single-threaded, but the Ignition UI, based on Java Swing, is. So code on a button press will by default run on whats known as the EDT, or Event Dispatch Thread. But you can easily make your script run in a background thread so the UI keeps on chugging.
