Ignition scripting

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.

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)

So you need to send an F7 keypress? Isn’t this what @witman 's post did here? Ignition scripting

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

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

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

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)

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.)

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"):

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.

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

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 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).

thank you so much for helping

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