FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   Getting mouse X/Y beyond app window
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Getting mouse X/Y beyond app window  (Read 467 times)
pitaru

WWW Email
Getting mouse X/Y beyond app window
« on: May 2nd, 2003, 9:15pm »

Is there a way to get the MouseX /MouseY position when the cursor is out of the application frame boundaries?
 
(Basically have it work like the mouseDragged Java event).
 
 
fry


WWW
Re: Getting mouse X/Y beyond app window
« Reply #1 on: May 3rd, 2003, 12:57am »

the fact that you can't currently is a bug that has sadly been languishing on the todo list for too long.
 
(moving this over to the bug reports area)
 
fry


WWW
Re: Getting mouse X/Y beyond app window
« Reply #2 on: Sep 1st, 2003, 6:52am »

this should now be working so long as it's a drag. you can start by clicking inside the app, then drag outside it and you'll still be getting mouse coords, via mouseDragged. is this not working? or has it been fixed in the meantime?
 
but you can't get coords on mouseMoved while the mouse is outside the applet area, that's just a java restriction.
 
fry


WWW
Re: Getting mouse X/Y beyond app window
« Reply #3 on: Sep 1st, 2003, 3:19pm »

comments back from amit on this:
 
it was a bit restricting for a project i had in mind. i never had to use it since. back then i solved the problem like this:
 
 // Convert a coordinate relative to a component's bounds to
desktop-screen coordinates
 Point topleft = new Point(0, 0);
 SwingUtilities.convertPointToScreen(topleft, this);
 
    // do the other way...
 Point pt = new Point(mouseX, mouseY);
 SwingUtilities.convertPointFromScreen(pt, this);
 
i don't know if anyone else will ever need it, but there you go...
 
(moving to syntax in case anyone ever runs into this)
 
kevinP

Email
Re: Getting mouse X/Y beyond app window
« Reply #4 on: Jun 12th, 2004, 12:35pm »

Hi all,
 
I'm using something like this to stop drawing when the curser is outside my window (so that I don't leave something that tracks the cursor pos. "hanging"...
Code:

  if(mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
    line(mouseX,mouseY, l.x[0],l.y[0]);
    line(mouseX,mouseY, l.x[1], l.y[1]);
  }

 
But if one moves at even a moderate speed the mouse position will often go outside without updating mouseX/mouseY and this leaves me with a mouseX value of, say, 198, when it should be 200 (or greater).
 
Is there a better way to do this?  
 
I don't see from the code posted above how I would return x/y coordinates relative to my window.
 
-K
 

Kevin Pfeiffer
fry


WWW
Re: Getting mouse X/Y beyond app window
« Reply #5 on: Jun 14th, 2004, 8:19pm »

unfortunately it's a java restriction. the mouse events aren't passed in for anything that's outside the space of the screen "owned" by the applet's box.
 
kevinP

Email
Re: Getting mouse X/Y beyond app window
« Reply #6 on: Jun 15th, 2004, 11:22pm »

Maybe there is a way to at least know if the mouse has left the applet box. Looking at Interface MouseListener in the Java docs I see "A mouse event is also generated when the mouse cursor enters or leaves a component...".
 

Kevin Pfeiffer
fry


WWW
Re: Getting mouse X/Y beyond app window
« Reply #7 on: Jun 16th, 2004, 1:31am »

yup, which you can grab just like any java application by overriding the "mouseExited" method.
 
Pages: 1 

« Previous topic | Next topic »