# Desktop Focus Event Handler

**URL:** <https://forum.inductiveautomation.com/t/desktop-focus-event-handler/28390>\
**Category:** Ignition\
**Tags:** ignition79, scripting\
**Created:** [September 19, 2019, 3:16pm UTC](https://forum.inductiveautomation.com/t/desktop-focus-event-handler/28390 "2019-09-19T15:16:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bfuson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfuson/32/4597_2.png) [@bfuson](https://forum.inductiveautomation.com/u/bfuson)\
**Post date:** [September 19, 2019, 3:16pm UTC](https://forum.inductiveautomation.com/t/desktop-focus-event-handler/28390/1 "2019-09-19T15:16:01Z")

</div>

I have a script that needs to execute every time a desktop gains focus.  
The desktop contains one simple window, and serve as a screen-independent popup.  
The internalFrameActivated event handler on the actual window doesn’t fire in this instance. It only fires when the desktop first opens and not whenever focus is gained.

---

<div class="post-metadata">

**Author:** ![bfuson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfuson/32/4597_2.png) [@bfuson](https://forum.inductiveautomation.com/u/bfuson)\
**Post date:** [September 19, 2019, 8:52pm UTC](https://forum.inductiveautomation.com/t/desktop-focus-event-handler/28390/2 "2019-09-19T20:52:59Z")

</div>

I think I’ve exhausted all options to no success.

- Adding a WindowFocusListener to the desktop object after creating it with system.gui.createDesktop() doesn’t seem to work, as the listener never seems to trigger once added?
- Adding a FocusListener or a ComponentListener to a component inside the desktop doesn’t work, as the component doesn’t reliably gain focus upon clicking the window or titlebar.
- Using a client expression tag that runs system.gui.getCurrentDesktop() always returns ‘primary’, so you can’t cheat in that way either.

The half-solution I’m using now is a click event on the window, which doesn’t fire when the window gains focus by clicking the titlebar. ☹
