Button KeyPressed Scripting

I attempted to follow this forum thread to find my answer, but for some reason I am still unable to get my desired result.

I am making a menu that will switch screens based on a click or a keyPressed which in this case happens to be F2. I looked over the class KeyEvent and thought that the code would work but I am not seeing the navigation occur. Is there something obvious that is wrong with the way I have the script?

Ignition scripting - Ignition - Inductive Automation Forum

2022-11-09 08_29_03-Arconic - Ignition-ETGENGLT497 - Ignition Designer
The Button I have 2 action events attached to.


This is the script for the keyPressed event

Also, I know that the code should really read event.VK_F2 for the F2 key but I was attempting to troubleshoot.
I also attempted to place a system.gui.messageBox("test") as a test but still no result.

First things first: Is there anything in your logs ? Do they say anything when you click that button ?

@pascal.fragnoud are you referring to the Gateway logs or the Console from the Diagnostic screen Ctrl-Shift-F7?

Either way it does not appear that I am getting any feedback on either when I press the 'a' button

Have you tried using a Client Keystroke Event Script?

You should probably be using system.nav.swapTo

Place a print event.keyCode prior to the if statement.

Place a print 'Key Pressed!' inside of the if statement to see if the code is getting inside the if.

Have you verified that the path to the window is correct?

1 Like

@lrose I have tried the Client Keystroke Event Script and it does in fact work. The issue I have with it is that you can press the key on any screen and then navigate to the desired page. We really only wanted access to that functionality on one page not anywhere in the client.

I have switched the code around so that it now shows print statements. Does the keyCode ever have to be defined by chance? Also, which area will I see the print statements. In the designer is it under Tools / Console?

The path shouldn't have been the issue since I copied it from the window I wish to move to and the name hasn't been changed.

You just need to do a little more filtering:


if system.nav.getCurrentWindow() != "Path/To/WantedParentWindow":
     system.nav.swapTo("Furnaces")
1 Like

Another element that is weird.

If I press the Preview in the designer, it actually works and will navigate to the other window. However, once I launch the project through the designer the functionality no longer works. Does it matter that this is a popup?

EDIT: It seems that the functionality is not limited because it is a popup. Is scripting limited to the point it wouldn't work in the windowed launch?

You are struggling because event handlers in java Swing consume events at the innermost focused component where a handler is defined, and only "bubble" outwards when there's no handler there. Any input component that has focus will consume key events that you are trying to handle at an outer layer. The client event key handler hooks into the application at a point before Swing tries to follow its focus rules.

Use the Client keystroke handler event, not a component event.

@pturmel I understand now, hmm.... Is there a way to transfer focus to the popup menu then?

I would prefer not to use the client keystroke because you can access them even when you are no on the window that would display them.

Inside the client event script, decide to act or not based on the current window, as @lrose has already pointed out.