Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Current mouse location...

 
G Estes
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would you capture the current mouse location at a given time? Specifically, the Point on the screen where the mouse pointer is located.
 
Rene Liebmann
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a component, then this component can catch every mouse event, for example mouse moved event. This event keeps the information of the current position. You can hold this information in a member (Point) and if the time comes, where you need the information, you will have it. This is the way I would go.
 
Jawad Kakar
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if e is MouseEvent then
int x = e.getX();
int y = e.getY();
would be the point where the mouse was clicked.
Jawad
 
G Estes
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess I wasn't clear. If the mouse is not clicked, and not over my component and the user presses some key (F6 for instance), at that point I want to use the Robot class to do some things with the mouse, move it, click some things, etc...and then return it to it's original location. So what I need is a way to get the original (current) location of the mouse without having to depend on the MouseEvent.
Ideas?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the mouse is not in a component listening for mouse events (i.e. if it's hanging out on the windows desktop outside of your application) then there's nothing you can do to get the mouse location. Searching for resources on this led me to find there used to be a class called EventQueueMonitor in some really early com.sun package for Java Accessability that did this, but there is no way currently provided to do this...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic