Good Afternoon, I have been asked if it is possible to bind keys from the PC Keyboard (F3 for example) to a button on an Ignition Screen. For example, if we are saving a recipe, you could click the “Save” button on the Ignition screen but also if you press F3 it would accomplish the same function.
Yes you should be able to using
.doClick(). In a client event script, keystroke event, add a script like so
main = system.gui.getWindow("your Window") button = main.getRootContainer().getComponent("yourButton") button.doClick()
A much more reusable approach - put any and all non-trivial business logic into project scoped scripts. Have keystroke scripts or button
actionPerformed simply call those scripts.
So “your Window” would be the window the button resides
“yourButton” would be the button I want to simulate with an actual keyboard stroke.
button.doClick() would be the key i choose to use like (F3) ?
I thought of that as an alternative to
.doClick(), just call the same project script from either the button or the keystroke.
As @PGriffith mentioned, it would be best to put the script into the project script library. Then call the script from the button or the keystroke. IE
As far as the
.doClick() goes, the entire script I gave would be in the keystroke event script
That seems very simple and straight forward. so in the case you presented, the F3 button would only have one task. By adding additional script, it could do tasks on other screens, correct?
You may want to check to make sure the window is open before you try to run a script involving that window. Probably would involve system.gui.getOpenedWindowNames()
windows = system.gui.getOpenedWindowNames() if 'window1' in windows: do this...
This F3 keystroke is a project event script, so it will only do this for the project. Every project could have an F3 event that did something different, but for different windows in the same project you need to check which window is open etc, before running the script.
Got it. Thank you very much for your help.