# Scripting a button press to turn on a PLC tag

**URL:** <https://forum.inductiveautomation.com/t/scripting-a-button-press-to-turn-on-a-plc-tag/55964>\
**Category:** Ignition\
**Created:** [February 10, 2022, 5:46am UTC](https://forum.inductiveautomation.com/t/scripting-a-button-press-to-turn-on-a-plc-tag/55964 "2022-02-10T05:46:43Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![jhansen](https://avatars.discourse-cdn.com/v4/letter/j/59ef9b/32.png) [@jhansen](https://forum.inductiveautomation.com/u/jhansen)\
**Post date:** [February 10, 2022, 6:43am UTC](https://forum.inductiveautomation.com/t/scripting-a-button-press-to-turn-on-a-plc-tag/55964/5 "2022-02-10T06:43:06Z")

</div>

This forum post gives a good solution;

> [@Perspective: Scripting a Momentary Button](https://forum.inductiveautomation.com/t/perspective-scripting-a-momentary-button/35684):
>
> Hey folks, Ignition 8.0.7 I’m trying to implement a momentary button in Perspective, but the feature doesn’t appear to be available. The One-Shot Button documentation states, [“If your PLC expects the HMI to reset the bit, use the Momentary Button.”](https://docs.inductiveautomation.com/display/DOC80/Perspective+-+One-Shot+Button) Since it seems as though the feature is not yet supported, does anyone have an example script for the button component that can reliably perform the Momentary function? I’m having a hard time replicating the function of the momentary button from Vi…

It's best to have a button set the value to 1 using a script. (Right click the button -\> Configure Events, then use the system.tag.writeBlocking() function to write to the tag). Then program the PLC to reset the value back to 0 after a given time.

If you want to do this only from ignition, refer to the forum post and use some form of sleep() or threading.Timer to write a 0 back to the tag after a specified time.

---

_[View the full topic](https://forum.inductiveautomation.com/t/scripting-a-button-press-to-turn-on-a-plc-tag/55964)._
