Client Escape Keystroke Script does not fire when button has focus

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?

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

2 Likes

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

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

Example:

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

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.

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 ---")
1 Like

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. :man_shrugging:

1 Like