Components blocking mouseMoved event script

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?

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]

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?

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]

Glad to see you have it worked out!

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.

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?

[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.

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.

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