# Mouseexit handle close window not working

**URL:** <https://forum.inductiveautomation.com/t/mouseexit-handle-close-window-not-working/63478>\
**Category:** Ignition\
**Tags:** ignition78, vision\
**Created:** [August 25, 2022, 10:12pm UTC](https://forum.inductiveautomation.com/t/mouseexit-handle-close-window-not-working/63478 "2022-08-25T22:12:23Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [August 25, 2022, 10:12pm UTC](https://forum.inductiveautomation.com/t/mouseexit-handle-close-window-not-working/63478/1 "2022-08-25T22:12:23Z")

</div>

Hello

I go into the popups root container and set it to close the window on the mouseexited event handler. But it closes before the mouse exits the window…

Any ideas why this is happening? I need to close the popups automatically because apparently production has thick fingers and clicking a button just doesn’t cut it.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [August 26, 2022, 11:24am UTC](https://forum.inductiveautomation.com/t/mouseexit-handle-close-window-not-working/63478/3 "2022-08-26T11:24:35Z")

</div>

I know @dawid_styczynski had mentioned the onKeyPress event before he deleted it, but I think he’s close.

What about a mousePressed or mouseReleased event instead?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 26, 2022, 11:46am UTC](https://forum.inductiveautomation.com/t/mouseexit-handle-close-window-not-working/63478/4 "2022-08-26T11:46:09Z")

</div>

> [@andrews](#):
>
> I need to close the popups automatically because apparently production has thick fingers and clicking a button just doesn’t cut it.

Just make the button really big? 😆

> [@andrews](#):
>
> But it closes before the mouse exits the window…

How close to exiting? And is this a touch screen or are they actually using a mouse?

---

<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:** [August 26, 2022, 11:47am UTC](https://forum.inductiveautomation.com/t/mouseexit-handle-close-window-not-working/63478/5 "2022-08-26T11:47:00Z")

</div>

MouseExit triggers whenever the mouse leaves the component’s input scope for any other input scope _ **including its own children** _. That’s why it’s breaking for you.

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [August 26, 2022, 10:00pm UTC](https://forum.inductiveautomation.com/t/mouseexit-handle-close-window-not-working/63478/6 "2022-08-26T22:00:13Z")

</div>

@lrose in the middle of the container the script is on.

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [August 26, 2022, 10:02pm UTC](https://forum.inductiveautomation.com/t/mouseexit-handle-close-window-not-working/63478/7 "2022-08-26T22:02:35Z")

</div>

@JordanCClark well if they click a button on it. Let’s say a HOA for example. I don’t want to close it as they may need the HOA open to re click.

However when they click on the main window, I want that HOA closed as they are intentionally leaving it.

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [August 26, 2022, 10:03pm UTC](https://forum.inductiveautomation.com/t/mouseexit-handle-close-window-not-working/63478/8 "2022-08-26T22:03:21Z")

</div>

@pturmel makes sense. Any good suggestions for me to try a different route?

---

<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:** [August 27, 2022, 12:45am UTC](https://forum.inductiveautomation.com/t/mouseexit-handle-close-window-not-working/63478/9 "2022-08-27T00:45:19Z")

</div>

Consider using a timer component in the popup that you reset whenever there’s any events anywhere in the window. If it times out, it closes the popup.

---

<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:** [August 27, 2022, 1:51am UTC](https://forum.inductiveautomation.com/t/mouseexit-handle-close-window-not-working/63478/10 "2022-08-27T01:51:25Z")

</div>

The mouseExited event should work fine if you qualify it using the dimensions of the popup:

```auto
if event.x >= event.source.parent.parent.parent.size.width-20 or event.y >= event.source.parent.parent.parent.size.height-40 or event.x <= 20 or event.y <= 20:
	#Put close window command here

```

Edit: After experimenting with this, I realized that I had forgot to include the upper and left edges. This has been corrected. I also padded the margins a little bit to improve reliability.

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [August 29, 2022, 3:07pm UTC](https://forum.inductiveautomation.com/t/mouseexit-handle-close-window-not-working/63478/11 "2022-08-29T15:07:50Z")

</div>

@pturmel not a bad idea. I’ll have to do some research on an acceptable timeout delta.

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [August 29, 2022, 3:09pm UTC](https://forum.inductiveautomation.com/t/mouseexit-handle-close-window-not-working/63478/12 "2022-08-29T15:09:46Z")

</div>

@justinedwards.jle interesting idea. I’ll have to do some testing and play around with that idea.

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [September 21, 2022, 3:32pm UTC](https://forum.inductiveautomation.com/t/mouseexit-handle-close-window-not-working/63478/14 "2022-09-21T15:32:44Z")

</div>

@justinedwards.jle I tired that, and couldn’t get it working.

I was however able to get it a lot more stable with InternalFrameDeactivated now it only closes when i click one button

ahhh, its because someone has a confirmation script on that button, which does cause it to loose focus.

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [September 21, 2022, 7:40pm UTC](https://forum.inductiveautomation.com/t/mouseexit-handle-close-window-not-working/63478/15 "2022-09-21T19:40:30Z")

</div>

I was able to get it working perfectly with InternalFrameDeactivated and having it close the window

---

<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:** [September 22, 2022, 7:48am UTC](https://forum.inductiveautomation.com/t/mouseexit-handle-close-window-not-working/63478/16 "2022-09-22T07:48:57Z")

</div>

> [@andrews](#):
>
> @justinedwards.jle I tried that, and couldn’t get it working.

My guess would be that a component within the frame was touching the edge of the window and preventing the event. The following experiment illustrates this problem:

Here is a popup window that tracks and displays the mouse cursor position using the mouseMoved event handler. I have set a margin around the popup of 20 pixels, so any time the cursor travels within 20 pixels of the edge, the lower text field will display false, and if the goal is to close the window, a navigation close script would work here:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/8/180dabd7522181fb5388533e0b1a1f8afb62e1e3.png)

Now, if I enter the text field from the bottom while the cursor is within the margines, the mouse cursor stops being tracked, and if it approaches the margin and leaves the popup, the bool will not change state, and the window close script will not fire:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/f/5f9dabb9f0aba40f3eba0eedb85b901cb7075cac.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/3/f3c436d590b04a1d5a66255c761dc82364e553ae.png)

As you can see, the only way for the mouse script to work, is if the margins around the popup are not covered by other components:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/0/b08295eee4fc5c0855f0eaccc966f9fa16ff59eb.png)

Therefore, to be successful using a mouse exited script with boundary constraints **on the container itself** , you would have to make sure that none of the internal components were touching the edge, and you would have to set the minimum size parameters of the popup to prevent users from sizing the window in such a way that would cause a component to overlap the edge.

Here is the code I used, in case you want to experiment with this yourself:

```auto
e = event
margin = 20
x2 = e.source.width - margin
y2 = e.source.height - margin
withinMargines = "False"
if e.x > margin and e.y > margin and e.x < x2 and e.y < y2:
	withinMargines = "True"
event.source.getComponent('Text Field').text = "Current mouse coordinates: ("+str(e.x)+", "+str(e.y)+")"
event.source.getComponent('Text Field 1').text = "Curser Within Margines = "+withinMargines

```

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [September 22, 2022, 2:50pm UTC](https://forum.inductiveautomation.com/t/mouseexit-handle-close-window-not-working/63478/17 "2022-09-22T14:50:29Z")

</div>

Thanks, I will play around with it more. Either way the scripted popup causes issues and its hard to control where that opens. I’m working on a way to not need that which will simplify the system a lot.
