# Ignition scripting

**URL:** <https://forum.inductiveautomation.com/t/ignition-scripting/32450>\
**Category:** Ignition\
**Created:** [February 20, 2020, 3:50am UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450 "2020-02-20T03:50:55Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![epifanio.tigno](https://avatars.discourse-cdn.com/v4/letter/e/57b2e6/32.png) [@epifanio.tigno](https://forum.inductiveautomation.com/u/epifanio.tigno)\
**Post date:** [February 20, 2020, 3:50am UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/1 "2020-02-20T03:50:55Z")

</div>

How can i key press an F12 to a BUTTON? Is there a way i can do it in ignition?

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [February 20, 2020, 12:23pm UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/2 "2020-02-20T12:23:59Z")

</div>

Under Project-Scripts-Client Event Scripts  
Keystroke scripts. Add one for F12

---

<div class="post-metadata">

**Author:** ![epifanio.tigno](https://avatars.discourse-cdn.com/v4/letter/e/57b2e6/32.png) [@epifanio.tigno](https://forum.inductiveautomation.com/u/epifanio.tigno)\
**Post date:** [February 21, 2020, 8:21am UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/3 "2020-02-21T08:21:26Z")

</div>

how can i incorporate it to a button  
for example a a button  
submit  
the keystroke i want to incorporate with is F7  
when i press that F7(SUBMIT BUTTON) I will the integer/weight in a numeric text field?

---

<div class="post-metadata">

**Author:** ![rbabcock](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rbabcock/32/13425_2.png) [@rbabcock](https://forum.inductiveautomation.com/u/rbabcock)\
**Post date:** [February 21, 2020, 12:41pm UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/4 "2020-02-21T12:41:44Z")

</div>

You can add a script to the button’s keyPressed or keyReleased event handlers that will push the button for you when you press F7. it would look something like:

```auto
if event.keyCode == event.VK_F7:
    event.source.doClick()

```

This will trigger the actionPerformed script for that button.

---

<div class="post-metadata">

**Author:** ![epifanio.tigno](https://avatars.discourse-cdn.com/v4/letter/e/57b2e6/32.png) [@epifanio.tigno](https://forum.inductiveautomation.com/u/epifanio.tigno)\
**Post date:** [February 24, 2020, 2:41am UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/5 "2020-02-24T02:41:55Z")

</div>

> [@rbabcock](#):
>
> ```auto
> if event.keyCode == event.VK_F7:
> event.source.doClick()
> 
> ```

its not working  
shall i put that code in scripting functions to a button?

---

<div class="post-metadata">

**Author:** ![epifanio.tigno](https://avatars.discourse-cdn.com/v4/letter/e/57b2e6/32.png) [@epifanio.tigno](https://forum.inductiveautomation.com/u/epifanio.tigno)\
**Post date:** [February 24, 2020, 3:58am UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/6 "2020-02-24T03:58:20Z")

</div>

> [@rbabcock](#):
>
> if event.keyCode == event.VK\_F7: event.source.doClick()

i have tried it but i doesn't refresh the data incorporated to F7  
I have weighing that prints the weight as F7, and i want to incorporate the F7 to a button in ignition. I have tried the code you have given. As i press the button it sends the weight to a numeric field but only when i pressed the key F7.

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [February 24, 2020, 4:12am UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/7 "2020-02-24T04:12:50Z")

</div>

Do you want tapping the button to create an F7 key press? If so, you could try something like this in the actionPerformed event on the button:

```python
from java.awt import Robot
from java.awt.event import KeyEvent

robot = Robot()
robot.keyPress(KeyEvent.VK_F7)
robot.keyRelease(KeyEvent.VK_F7)

```

---

<div class="post-metadata">

**Author:** ![epifanio.tigno](https://avatars.discourse-cdn.com/v4/letter/e/57b2e6/32.png) [@epifanio.tigno](https://forum.inductiveautomation.com/u/epifanio.tigno)\
**Post date:** [February 24, 2020, 5:55am UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/8 "2020-02-24T05:55:13Z")

</div>

yes, i want to make the button as may F7 key  
i tried your code it doesnt work also  
appreciate it much for helping  
thank you all of you guys

---

<div class="post-metadata">

**Author:** ![epifanio.tigno](https://avatars.discourse-cdn.com/v4/letter/e/57b2e6/32.png) [@epifanio.tigno](https://forum.inductiveautomation.com/u/epifanio.tigno)\
**Post date:** [February 24, 2020, 7:18am UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/9 "2020-02-24T07:18:15Z")

</div>

im tryng to install pynput  
it doesnt work also  
do you have idea how to make pynput work?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 24, 2020, 12:36pm UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/10 "2020-02-24T12:36:18Z")

</div>

I verified that @witman’s code does, in fact, work with two separate utilities I use.

An easy test of the code would be to change F7 to F1 and see if it launches the help webpage.

Maybe if you explained what you are trying to accomplish, we may be able to better help you. 🙂

---

<div class="post-metadata">

**Author:** ![rbabcock](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rbabcock/32/13425_2.png) [@rbabcock](https://forum.inductiveautomation.com/u/rbabcock)\
**Post date:** [February 24, 2020, 1:09pm UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/11 "2020-02-24T13:09:17Z")

</div>

Yes, I misunderstood what you were attempting. The code I posted is just a keybinding for the button; sorry about that.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 24, 2020, 1:23pm UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/12 "2020-02-24T13:23:18Z")

</div>

> [@epifanio.tigno](#):
>
> how can i incorporate it to a button  
> for example a a button  
> submit  
> the keystroke i want to incorporate with is F7  
> when i press that F7(SUBMIT BUTTON) I will the integer/weight in a numeric text field?

Sorry, ignore my previous part. 🙂

If I'm reading this correctly, @rbabcock was on the right track, but what you need is a keystroke client event script. Keep in mind that you will need to monitor that the correct window is open.

 ![2020-02-24_8-22-29](https://us1.discourse-cdn.com/inductiveautomation/original/2X/f/fc0211cc7374e60b2d99ddf394740412fcebee5c.png)

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [February 24, 2020, 4:02pm UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/13 "2020-02-24T16:02:09Z")

</div>

@epifanio.tigno:

1. Do you want a button pressed in Ignition to create an F7 key press? If so, the code I posted does that… but there are some more details that affect whether this will work for what you’re trying to do:  
a) Where do you press F7 now that you’re trying to replace with a button in Ignition? On some other device, like a scale? Or on the computer keyboard running an Ignition HMI?  
b) Is it Ignition or some other program that normally has the focus when you press the F7 button?

2. Or do you want pressing F7 to press a button in Ignition? If so, see @rbabcock’s and @JordanCClark’s posts above.

---

<div class="post-metadata">

**Author:** ![epifanio.tigno](https://avatars.discourse-cdn.com/v4/letter/e/57b2e6/32.png) [@epifanio.tigno](https://forum.inductiveautomation.com/u/epifanio.tigno)\
**Post date:** [February 26, 2020, 12:33am UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/14 "2020-02-26T00:33:51Z")

</div>

yes sir @witman, i want my button act as an F7 ,i want to replace the F7 to act in a button in my HMI,i am using a weighing scale device with a configuration of F7 to work or to capture its weight and show it the captured weight to a numeric field.

---

<div class="post-metadata">

**Author:** ![epifanio.tigno](https://avatars.discourse-cdn.com/v4/letter/e/57b2e6/32.png) [@epifanio.tigno](https://forum.inductiveautomation.com/u/epifanio.tigno)\
**Post date:** [February 26, 2020, 12:34am UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/15 "2020-02-26T00:34:45Z")

</div>

yep its okay, thanks for helping

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [February 26, 2020, 12:48am UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/16 "2020-02-26T00:48:34Z")

</div>

Where do you press F7 now? On the scale? Or on a keyboard connected to the computer running the Ignition HMI?

---

<div class="post-metadata">

**Author:** ![epifanio.tigno](https://avatars.discourse-cdn.com/v4/letter/e/57b2e6/32.png) [@epifanio.tigno](https://forum.inductiveautomation.com/u/epifanio.tigno)\
**Post date:** [February 26, 2020, 1:16am UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/17 "2020-02-26T01:16:05Z")

</div>

right now on a keyboard, but i want is pressing a BUTTON that act as an F7 (keyboard)

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [February 26, 2020, 1:43am UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/18 "2020-02-26T01:43:21Z")

</div>

If you’re pressing F7 on the computer keyboard and that is working, the [code I posted above](http://forum.inductiveautomation.com/t/ignition-scripting/32450/7) does create an F7 key press when you press a button with that code in the action performed script of the button like this.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/f/f8761ecede17703b191a8c0d228fecba002db5cd.png)  
If this does not work for your application, the next question is where is the focus when you press F7 on the keyboard and it works? Is the focus/cursor in a component in Ignition or in another program?

---

<div class="post-metadata">

**Author:** ![epifanio.tigno](https://avatars.discourse-cdn.com/v4/letter/e/57b2e6/32.png) [@epifanio.tigno](https://forum.inductiveautomation.com/u/epifanio.tigno)\
**Post date:** [February 27, 2020, 3:53am UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/19 "2020-02-27T03:53:21Z")

</div>

that code actually works as a keypress  
but the problem is i have to press first the F7 in keyboard before it captures the actual weght.  
Sorry im having a harding time for expalining hehe  
thanks

---

<div class="post-metadata">

**Author:** ![epifanio.tigno](https://avatars.discourse-cdn.com/v4/letter/e/57b2e6/32.png) [@epifanio.tigno](https://forum.inductiveautomation.com/u/epifanio.tigno)\
**Post date:** [February 27, 2020, 3:57am UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/20 "2020-02-27T03:57:57Z")

</div>

is there a key event the refreshes after pressing the button?

[Next page](https://forum.inductiveautomation.com/t/ignition-scripting/32450.md?page=2)
