# Check with scripting if mouse is over certain object

**URL:** <https://forum.inductiveautomation.com/t/check-with-scripting-if-mouse-is-over-certain-object/69938>\
**Category:** Ignition\
**Tags:** scripting, ignition80, vision\
**Created:** [February 16, 2023, 3:13pm UTC](https://forum.inductiveautomation.com/t/check-with-scripting-if-mouse-is-over-certain-object/69938 "2023-02-16T15:13:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevin\_Hens](https://avatars.discourse-cdn.com/v4/letter/k/53a042/32.png) [@Kevin\_Hens](https://forum.inductiveautomation.com/u/Kevin_Hens)\
**Post date:** [February 16, 2023, 3:13pm UTC](https://forum.inductiveautomation.com/t/check-with-scripting-if-mouse-is-over-certain-object/69938/1 "2023-02-16T15:13:41Z")

</div>

Hi,

I would like to know if there is a programmatically way to check if the mouse is over a component.  
I would expect a button object already has something build in that I should be able to fetch?

The reason I need this is that I draw some custom components using a paintable canvas.  
As an example, I use: event.source.parent.getComponent('btnOverlay').isFocusOwner() to check if my button is the focus owner, depending on that I draw a focus rectangle.

The way I do it now is by setting a custom property with the mouseEntered event and resetting the custom property with the mouseExited event.  
The problem here is that if my button closes the window and I reopen it, it remains highlighted since the cutom property is not updating.  
So a direct programmatically way should solve this.

Thanks in advance!

---

<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:** [February 16, 2023, 3:31pm UTC](https://forum.inductiveautomation.com/t/check-with-scripting-if-mouse-is-over-certain-object/69938/2 "2023-02-16T15:31:52Z")

</div>

This has worked well for me in the past in a similar situation

[Component Events - Ignition User Manual 8.1 - Ignition Documentation (inductiveautomation.com)](https://docs.inductiveautomation.com/display/DOC81/Component+Events#ComponentEvents-InternalFrameEventHandlers)

---

<div class="post-metadata">

**Author:** ![Kevin\_Hens](https://avatars.discourse-cdn.com/v4/letter/k/53a042/32.png) [@Kevin\_Hens](https://forum.inductiveautomation.com/u/Kevin_Hens)\
**Post date:** [February 16, 2023, 4:40pm UTC](https://forum.inductiveautomation.com/t/check-with-scripting-if-mouse-is-over-certain-object/69938/3 "2023-02-16T16:40:32Z")

</div>

Yeah I'm aware of these component events. But they don't fully cover my issue. Since the mouseExit event does't occur whenever the page is closed on click.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 16, 2023, 4:56pm UTC](https://forum.inductiveautomation.com/t/check-with-scripting-if-mouse-is-over-certain-object/69938/4 "2023-02-16T16:56:07Z")

</div>

Every Swing component has a `getMousePosition()` method that returns a value if the mouse is directly over the component and null otherwise:  
[https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/java/awt/Component.html#getMousePosition()](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/java/awt/Component.html#getMousePosition())

---

<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:** [February 16, 2023, 5:03pm UTC](https://forum.inductiveautomation.com/t/check-with-scripting-if-mouse-is-over-certain-object/69938/5 "2023-02-16T17:03:27Z")

</div>

But the internalFrameDeactivated would work this way. Which is why I have used it instead of the mouseExit.

---

<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:** [February 16, 2023, 5:06pm UTC](https://forum.inductiveautomation.com/t/check-with-scripting-if-mouse-is-over-certain-object/69938/6 "2023-02-16T17:06:10Z")

</div>

I really need to get better at exploring these docs.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [February 16, 2023, 5:34pm UTC](https://forum.inductiveautomation.com/t/check-with-scripting-if-mouse-is-over-certain-object/69938/7 "2023-02-16T17:34:18Z")

</div>

You can do an on-close event or on-open event to reset all of the custom properties changed by the onMouseEnter/Exit events

---

<div class="post-metadata">

**Author:** ![Kevin\_Hens](https://avatars.discourse-cdn.com/v4/letter/k/53a042/32.png) [@Kevin\_Hens](https://forum.inductiveautomation.com/u/Kevin_Hens)\
**Post date:** [February 16, 2023, 11:33pm UTC](https://forum.inductiveautomation.com/t/check-with-scripting-if-mouse-is-over-certain-object/69938/8 "2023-02-16T23:33:50Z")

</div>

Hi amarks, I'm also aware of that, but I'd rather figure it out on my custom component level than on the page event properties to keep everything within the object.

---

<div class="post-metadata">

**Author:** ![Kevin\_Hens](https://avatars.discourse-cdn.com/v4/letter/k/53a042/32.png) [@Kevin\_Hens](https://forum.inductiveautomation.com/u/Kevin_Hens)\
**Post date:** [February 17, 2023, 1:27pm UTC](https://forum.inductiveautomation.com/t/check-with-scripting-if-mouse-is-over-certain-object/69938/9 "2023-02-17T13:27:39Z")

</div>

> [@andrews](#):
>
> get better at exploring thes

Did the job! Thanks!
