# 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:** 13\
**Page:** 2

<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 27, 2020, 5:24am UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/21 "2020-02-27T05:24:51Z")

</div>

When you press F7 on the keyboard and it captures the weight, do you need to have the cursor in the numeric text field first? Does the sequence of actions that works go like this?

1. Put cursor in numeric text field.
2. Press F7 on keyboard. Weight from scale is entered into text field.

If so, we’d need to add to the script to have the numeric text field requestFocusInWindow() before creating the F7 key event.

Can you confirm that you are _not_ pressing F7 on the scale’s keyboard? If you are pressing F7 _on the scale’s keyboard_ (NOT the computer’s keyboard), creating an F7 key press on the computer is almost certainly _not_ going to work.

---

<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, 5:54am UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/22 "2020-02-27T05:54:24Z")

</div>

yup 1 and 2 is correct sir  
The F7 is in the keyboard of my Desktop  
What i am trying to say is that i want F7(Keyboard) to be incorporated to a button so that i would not press the F7 anymore.  
What happens is that i weigh an item on the scale i still have to press the F7(Keyboard) to update/refresh the captured weight on the scale and then i can now press the button(with the keypress on ignition)  
Its like the captured weight is not updating until i press first the F7(KEYBOARD)

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [February 27, 2020, 8:39am UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/23 "2020-02-27T08:39:24Z")

</div>

So you need to send an F7 keypress? Isn’t this what @witman 's post did here? [Ignition scripting](http://forum.inductiveautomation.com/t/ignition-scripting/32450/18?u=nminchin)

---

<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, 8:46am UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/24 "2020-02-27T08:46:02Z")

</div>

yes actually the code is really working  
but it doesnt satisfy what i want  
i guess i should really use an scale and connect to a plc

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [February 27, 2020, 8:49am UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/25 "2020-02-27T08:49:01Z")

</div>

This might be silly, but what happens if you call the press/release lines twice to press it 2 times

---

<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, 8:52am UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/26 "2020-02-27T08:52:02Z")

</div>

yeah and i still to have to press F7 on my keyboard to have an updated captured weight

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [February 27, 2020, 9:01am UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/27 "2020-02-27T09:01:36Z")

</div>

What application is communicating to the weight scale? You might need to pass the keypress to that application instead (@witman mentioned this in a previous post)

---

<div class="post-metadata">

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

</div>

Please describe how this hardware is currently hooked up. (I’m gonna guess that the computer keyboard plugs into the scale, which then plugs into the computer. Catching F7 _ **in hardware** _.)

---

<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 27, 2020, 4:42pm UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/29 "2020-02-27T16:42:54Z")

</div>

> [@epifanio.tigno](#):
>
> yup 1 and 2 is correct

Then the code will need to focus the numeric entry field before pressing F7, something like this (assumes your numeric entry field has the same parent as the button this code is on and has the default name "Numeric Text Field"):

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

# Focus field for weight entry.
numericField = event.source.parent.getComponent('Numeric Text Field')
numericField.requestFocusInWindow()

# Set field to a known value we can clear (assumes you're using floatValue, not intValue, etc.).
numericField.floatValue = 0

robot = Robot()
# Clear the zero (so it isn't appended to the end of new value).
robot.keyPress(KeyEvent.VK_DELETE)
robot.keyRelease(KeyEvent.VK_DELETE)
# Create an F7 key press.
robot.keyPress(KeyEvent.VK_F7)
robot.keyRelease(KeyEvent.VK_F7)

```

All that said, most likely you need the F7 key press to go to an external application that communicates with the scale, which will require some changes.

---

<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:** [March 2, 2020, 3:20am UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/30 "2020-03-02T03:20:52Z")

</div>

the scale is connected to my laptop via bluetooth,and it can be configure to capture the weight by its config changing it to F7,F4,SHIFT +A,or F11

---

<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:** [March 3, 2020, 5:35pm UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/31 "2020-03-03T17:35:04Z")

</div>

So you have a driver/program that catches those key presses to communicate with the scale. You’d need to find a way to get the key press to that driver/program. While the robot can do this by clicking on another window, and then sending the key press, that won’t work as you need the focus in the numeric entry field when you send the key press to the driver/program that communicates with the scale.

[This Python project](https://github.com/boppreh/keyboard) looks like it may be able to accomplish what you need–simulating global keyboard events on Windows/Linux (disclaimer: my knowledge of this one is limited to a cursory scan of the project home page).

---

<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:** [March 5, 2020, 7:56am UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/32 "2020-03-05T07:56:35Z")

</div>

thank you so much for helping

---

<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:** [March 5, 2020, 8:07am UTC](https://forum.inductiveautomation.com/t/ignition-scripting/32450/33 "2020-03-05T08:07:08Z")

</div>

i tried to copy the folder where .py is located and i tried to call the import keyboard  
to a button action performed it shows and error unsupported platform

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