# Client Escape Keystroke Script does not fire when button has focus

**URL:** <https://forum.inductiveautomation.com/t/client-escape-keystroke-script-does-not-fire-when-button-has-focus/89103>\
**Category:** Ignition\
**Tags:** vision, scripting\
**Created:** [April 19, 2024, 11:21am UTC](https://forum.inductiveautomation.com/t/client-escape-keystroke-script-does-not-fire-when-button-has-focus/89103 "2024-04-19T11:21:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![electricschmidt](https://avatars.discourse-cdn.com/v4/letter/e/6f9a4e/32.png) [@electricschmidt](https://forum.inductiveautomation.com/u/electricschmidt)\
**Post date:** [April 19, 2024, 11:21am UTC](https://forum.inductiveautomation.com/t/client-escape-keystroke-script-does-not-fire-when-button-has-focus/89103/1 "2024-04-19T11:21:33Z")

</div>

I've set up a client keystroke script bound to the escape key when it is pressed. It determines which windows are pop ups (implicitly by checking maximizable/isMaximized props) and closes the first one in the list. Seems to work fine. However, when a button has been pressed that can take focus (aka be 'tabbed' to), the script no longer fires. I think this is a problem specifically with using the escape key as I've tried it with other keys and it seems to work regardless of if a button has focus or not. Can anybody shed some light on if this is the expected behaviour (possibly because the escape key has special purpose in the whole button tabbing/focussing behaviour?) Or if this is a bug?

---

<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:** [April 19, 2024, 11:54am UTC](https://forum.inductiveautomation.com/t/client-escape-keystroke-script-does-not-fire-when-button-has-focus/89103/2 "2024-04-19T11:54:23Z")

</div>

Pretty sure this is java Swing behavior tied to "Cancel" default actions. You should use a different key.

---

<div class="post-metadata">

**Author:** ![pierre-marie.devigne](https://avatars.discourse-cdn.com/v4/letter/p/a5b964/32.png) [@pierre-marie.devigne](https://forum.inductiveautomation.com/u/pierre-marie.devigne)\
**Post date:** [December 9, 2025, 9:54am UTC](https://forum.inductiveautomation.com/t/client-escape-keystroke-script-does-not-fire-when-button-has-focus/89103/3 "2025-12-09T09:54:12Z")

</div>

No one has found a solution? I'd like my popups to close with the Esc key, which is pretty common.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [December 10, 2025, 5:58am UTC](https://forum.inductiveautomation.com/t/client-escape-keystroke-script-does-not-fire-when-button-has-focus/89103/4 "2025-12-10T05:58:29Z")

</div>

> [@pierre-marie.devigne](#):
>
> I'd like my popups to close with the Esc key,

I do this from Client Events using the escape keystroke event handler.

**Example:**

```python
selectedDesktop = 'someDesktop' # This is the handle for the current desktop that has focus

# Get all opened windows within the selected desktop
windows = system.gui.desktop(selectedDesktop).getOpenedWindows()

# Iterate through the windows and close the currently selected popup window [if it exists] 
for window in windows:
	isPopUp = ((not window.startMaximized) and (window.closable))
	if isPopUp and window.isSelected():
		system.nav.desktop(selectedDesktop).closeWindow(window)
		break

```

---

<div class="post-metadata">

**Author:** ![pierre-marie.devigne](https://avatars.discourse-cdn.com/v4/letter/p/a5b964/32.png) [@pierre-marie.devigne](https://forum.inductiveautomation.com/u/pierre-marie.devigne)\
**Post date:** [December 11, 2025, 2:29pm UTC](https://forum.inductiveautomation.com/t/client-escape-keystroke-script-does-not-fire-when-button-has-focus/89103/5 "2025-12-11T14:29:04Z")

</div>

I have a similar script. If I pair it with the Esc key, it works with some popups and not for others. The logger doesn't display anything. Don’t know why. I made the same script with the F1 key and it works every time.

```python
Obtenir une instance du logger. Vous pouvez nommer votre logger comme vous le souhaitez.

logger = system.util.getLogger("PopupLogger")

windows = system.gui.getOpenedWindows()
logger.info("--- Esc - Début du scan des fenêtres ---")

for window in windows:
try:
window_name = window.getName()
isPopUp = ((not window.startMaximized) and (window.closable))
isCurrentlySelected = window.isSelected()

    # Ligne de log mise à jour avec str.format()
    log_message = "Fenêtre: {}, IsPopup: {}, IsSelected: {}".format(window_name, isPopUp, isCurrentlySelected)
    logger.info(log_message)

    if (isPopUp and isCurrentlySelected):
        system.nav.closeWindow(window)
        # Autre ligne de log mise à jour
        logger.info("Fenêtre pop-up '{}' fermée par Esc.".format(window_name))
        break

except Exception as e:
    logger.error("Erreur lors du traitement de la fenêtre: {} - {}".format(window.getName(), e))

logger.info("--- Fin du scan des fenêtres ---")

```

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [December 11, 2025, 6:42pm UTC](https://forum.inductiveautomation.com/t/client-escape-keystroke-script-does-not-fire-when-button-has-focus/89103/6 "2025-12-11T18:42:56Z")

</div>

Interesting. I use popups for a lot of different things, and I've never once seen my script fail to close one. I'm guessing something else in our popup or button designs are inadvertently changing the focus behavior and allowing me to get away with it. 🤷‍♂️
