File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes How do I find mouse location Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How do I find mouse location" Watch "How do I find mouse location" New topic

How do I find mouse location

Tom Flanagan

Joined: Mar 03, 2004
Posts: 5
I know how to find a mouse location inside a Java JFrame - but is there any way to find the mouse location on the desktop (say in Windows xp) without being in a JFrame?
With Toolbox you can find the resolution of the desktop. With the robot class I can move the mouse around - butI can't find a way to find the current location of the mouse. Any help?
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Some night I'm going to answer a whole bunch of questions just by reading the subject line and not the actual note. Find the mouse by following the cord from the PC. It's out there on the end. Sorry, I'll go away now.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Igor Ko
Ranch Hand

Joined: Jun 24, 2002
Posts: 90
Yes... but if it's wireless mouse ???
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Originally posted by Igor Ko:
Yes... but if it's wireless mouse ???

Then you have to get the assistance of your cat.

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791

But we didn't help the poor guy much, did we.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
The only time I have seen mouse position messages when the mouse is outside the Java controlled area is when a mouse_down occurred inside the area and the button stayed down when the mouse moved outside.
I suspect that operating system specific native code would be required to get it otherwise. Basically, Java only gets mousemessages when the mouse is in the controlled area.
Charlie Hayes

Joined: Apr 27, 2004
Posts: 1
Download the new J2SE 1.5 SDK and use:
Hope that helps!
I agree. Here's the link:
subject: How do I find mouse location
It's not a secret anymore!