# Components blocking mouseMoved event script

**URL:** <https://forum.inductiveautomation.com/t/components-blocking-mousemoved-event-script/8056>\
**Category:** Ignition\
**Created:** [February 25, 2014, 9:02am UTC](https://forum.inductiveautomation.com/t/components-blocking-mousemoved-event-script/8056 "2014-02-25T09:02:07Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamthebull](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@iamthebull](https://forum.inductiveautomation.com/u/iamthebull)\
**Post date:** [February 25, 2014, 9:02am UTC](https://forum.inductiveautomation.com/t/components-blocking-mousemoved-event-script/8056/1 "2014-02-25T09:02:07Z")

</div>

I have a mouseMoved event script on the root container of a main window. The event script essentially grabs the x,y coordinates of the mouse cursor. The script does not execute if my mouse is moving over a component inside the root container, thus I loose track of my position on the screen when I’m over a component. How can I fix this?

Is there a layering to the components as there is for windows? Can I control this somehow?

---

<div class="post-metadata">

**Author:** ![greg.simpson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/greg.simpson/32/3135_2.png) [@greg.simpson](https://forum.inductiveautomation.com/u/greg.simpson)\
**Post date:** [March 7, 2014, 2:42pm UTC](https://forum.inductiveautomation.com/t/components-blocking-mousemoved-event-script/8056/2 "2014-03-07T14:42:15Z")

</div>

I spoke with iamthebull on the phone and sent him an example script. If anyone is interested, this is what I suggested

1. Make two client tags “MouseX” and “MouseY”
2. Place this script on a Client Startup Script

[code]

from java.awt import Toolkit  
from java.awt import AWTEvent  
from java.awt.event import AWTEventListener  
def eventDispatched(event):  
import system  
xy = system.gui.convertPointToScreen(event.x,event.y,event)  
system.tag.write("[Client]MouseX",xy[0])  
system.tag.write("[Client]MouseY",xy[1])

tk = Toolkit.getDefaultToolkit()  
tk.addAWTEventListener(eventDispatched, AWTEvent.MOUSE\_MOTION\_EVENT\_MASK)[/code]

---

<div class="post-metadata">

**Author:** ![iamthebull](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@iamthebull](https://forum.inductiveautomation.com/u/iamthebull)\
**Post date:** [March 7, 2014, 8:03pm UTC](https://forum.inductiveautomation.com/t/components-blocking-mousemoved-event-script/8056/3 "2014-03-07T20:03:36Z")

</div>

Thanks Greg.

This solves part of my problem.

The script is no longer being blocked by any components, however, these are not the coordinates I am looking for. The coordinates I want are with respect to the main window… not with respect to the entire screen. Can I modify this script to give the coordinates in the main window and not the screen?

---

<div class="post-metadata">

**Author:** ![iamthebull](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@iamthebull](https://forum.inductiveautomation.com/u/iamthebull)\
**Post date:** [March 7, 2014, 8:24pm UTC](https://forum.inductiveautomation.com/t/components-blocking-mousemoved-event-script/8056/4 "2014-03-07T20:24:21Z")

</div>

I think I figured it out. The following code gives me the coordinates with respect to the window:

[code]from java.awt import Toolkit  
from java.awt import AWTEvent  
from java.awt.event import AWTEventListener  
def eventDispatched(event):  
import system  
system.tag.write("[Client]MouseX",event.x)  
system.tag.write("[Client]MouseY",event.y)

tk = Toolkit.getDefaultToolkit()  
tk.addAWTEventListener(eventDispatched, AWTEvent.MOUSE\_MOTION\_EVENT\_MASK)[/code]

---

<div class="post-metadata">

**Author:** ![greg.simpson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/greg.simpson/32/3135_2.png) [@greg.simpson](https://forum.inductiveautomation.com/u/greg.simpson)\
**Post date:** [April 21, 2014, 5:00pm UTC](https://forum.inductiveautomation.com/t/components-blocking-mousemoved-event-script/8056/5 "2014-04-21T17:00:31Z")

</div>

Glad to see you have it worked out!

---

<div class="post-metadata">

**Author:** ![iamthebull](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@iamthebull](https://forum.inductiveautomation.com/u/iamthebull)\
**Post date:** [April 22, 2014, 5:32pm UTC](https://forum.inductiveautomation.com/t/components-blocking-mousemoved-event-script/8056/6 "2014-04-22T17:32:31Z")

</div>

Well, actually, in the end this did not work out. The script that I modified gave me the coordinates with respect to the window but when hovering over a component gave me the components with respect to that component.

---

<div class="post-metadata">

**Author:** ![The0dark0one](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@The0dark0one](https://forum.inductiveautomation.com/u/The0dark0one)\
**Post date:** [April 23, 2014, 2:29am UTC](https://forum.inductiveautomation.com/t/components-blocking-mousemoved-event-script/8056/7 "2014-04-23T02:29:39Z")

</div>

I can’t seem to reproduce your error.

On the root container, I put the following script into the mouseMoved handler.

`print event.x
print event.y`

When I mouse over any components, this still produces the correct coordinates with respect to the main window. Could you paste your script on here?

---

<div class="post-metadata">

**Author:** ![iamthebull](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@iamthebull](https://forum.inductiveautomation.com/u/iamthebull)\
**Post date:** [April 23, 2014, 3:11am UTC](https://forum.inductiveautomation.com/t/components-blocking-mousemoved-event-script/8056/8 "2014-04-23T03:11:49Z")

</div>

[code]x1 = event.x  
y1 = event.y

xval = event.source.getComponent(“xval”)  
xval.text = str(x1)

yval = event.source.getComponent(“yval”)  
yval.text = str(y1)[/code]  
xval and yval are text labels that display the coordinates. When I move over components on the screen these stop updating.

---

<div class="post-metadata">

**Author:** ![The0dark0one](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@The0dark0one](https://forum.inductiveautomation.com/u/The0dark0one)\
**Post date:** [April 23, 2014, 6:55pm UTC](https://forum.inductiveautomation.com/t/components-blocking-mousemoved-event-script/8056/9 "2014-04-23T18:55:40Z")

</div>

I was able to reproduce your error but only if the component that I moused over also had event handlers attached to mouse events.

I’ll assume disabling the component’s mouse event handlers is not an option.

Perhaps while inside the inside the component, try passing the event.x and event.y to event.source.getComponent(“xval”) and event.source.getComponent(“yval”). Doing this will pass X and Y values relative to the container, however. To adjust for this, you will need to know the position of your component. Simply use event.source.x and event.source.y to adjust the values.

`event.source.parent.getComponent('xval').text=str(event.x+event.source.x)
event.source.parent.getComponent('yval').text=str(event.y+event.source.y)
`  
Note: this script should be placed on your each of your components’ mouseMoved events.

---

<div class="post-metadata">

**Author:** ![dylan.malzinskas](https://avatars.discourse-cdn.com/v4/letter/d/67e7ee/32.png) [@dylan.malzinskas](https://forum.inductiveautomation.com/u/dylan.malzinskas)\
**Post date:** [April 13, 2021, 11:12pm UTC](https://forum.inductiveautomation.com/t/components-blocking-mousemoved-event-script/8056/10 "2021-04-13T23:12:04Z")

</div>

You can get the components location as you mouse over it with the event object that is passed in on the script given above, and not use the convertPointToScreen function so you can get the point relative to the window.

from java.awt import Toolkit  
from java.awt import AWTEvent  
from java.awt.event import AWTEventListener  
def eventDispatched(event):  
import system  
system.tag.write("[Client]MouseX",event.x+event.source.getLocation().x)  
system.tag.write("[Client]MouseY",event.y+event.source.getLocation().y)  
tk = Toolkit.getDefaultToolkit()  
tk.addAWTEventListener(eventDispatched, AWTEvent.MOUSE\_MOTION\_EVENT\_MASK)

This works for me even over components with events already on them
