determine the mouse cursor position without mouse event

T

tom arnall

is there a way to determine the mouse cursor position apart from
intercepting a mouse event such as drag, i.e., sometimes i want the cursor
position even if no mouse event has taken place

tom arnall
north spit, ca
usa



Loosen up: the tests extend the compiler.
 
J

John Ersatznom

tom said:
is there a way to determine the mouse cursor position apart from
intercepting a mouse event such as drag, i.e., sometimes i want the cursor
position even if no mouse event has taken place

What about trapping "mouse move" events? Every time the mouse moves to a
position inside your component it should generate one. If a mouse_pos
value pair is updated by a listener for such an event, it should always
hold the last position the mouse has had inside your component. If you
want the pos when it's outside the component, that may not be possible.
To know when it's left the component, just look for the pos to get near
the edge of the component and then not change for a while.
 
T

tom arnall

John said:
What about trapping "mouse move" events? Every time the mouse moves to a
position inside your component it should generate one. If a mouse_pos
value pair is updated by a listener for such an event, it should always
hold the last position the mouse has had inside your component. If you
want the pos when it's outside the component, that may not be possible.
To know when it's left the component, just look for the pos to get near
the edge of the component and then not change for a while.



That's the approach I use now: create a mouse move listener and update the
x,y values there for when I need them. But I seems to me that's a lot of
burden on the system, and I'm hoping that java gives more direct access to
the info. It seems to me that java tracks the info anyway, in order to make
the mousemove listener possible, so why not provide access to the info
without requiring a subroutine call e'time the cursor moves a pixel.

tom arnall
north spit, ca
usa
 
I

Ian Shef

is there a way to determine the mouse cursor position apart from
intercepting a mouse event such as drag, i.e., sometimes i want the cursor
position even if no mouse event has taken place
<snip>

I believe that MouseInfo.getPointerInfo() (in java.awt) will do what you
asked for,
but I think that adding a MouseMotionListener (in java.awt.event) and using
it to keep track is often a better way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top