We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Mouse window focus, and exiting window borders
Page Index Toggle Pages: 1
Mouse window focus, and exiting window borders (Read 390 times)
Mouse window focus, and exiting window borders
Feb 4th, 2009, 5:58am
 
Hey all.  I've been looking through the documentation, and not finding functions to do some things I'm looking to do.  I'm wondering if such functions exist, or if not, if anyone has advice on how to acheive such an effect.  These functions all relate to running sketches in a window as opposed to fullscreen.

What I'd most like, would be a function that prevents the mouse cursor/mouse input from leaving the sketch while the sketch window has focus.  In other words, I don't want the mouse to be able to scroll out of my sketch's window, unless I alt-tab to another program first.

Barring this, is there a function to determine which direction the mouse was moving when it left the window, i.e. which border it overran?  

Or would it make sense to use the "focused" keyword combined with a comparison between pmouseX/pmouseY and the window's width/height, to detect this?  That is, if I lose focus, and the pmouse value is near the value of width, then I can assume the mouse went off the right side of the window?

Any thoughts on this would be appreciated.  Thank you.
Re: Mouse window focus, and exiting window borders
Reply #1 - Feb 4th, 2009, 10:13am
 
I wonder what you are trying to achieve.
Constraining mouse cursor within the bounds of a window is (probably) against the "rules" of most windowing systems, as it might disorient users. Not everybody know how to get out of that with keyboard...

That said, you might want to take a look at the Robot class of Java, it allows to control cursor position. It have been mentioned a few times on this forum.
Re: Mouse window focus, and exiting window borders
Reply #2 - Feb 4th, 2009, 4:10pm
 
Well, some games, Unreal Tournament, for instance, act this way in windowed mode.  If they didn't, one would quickly find it impossible to turn around as far as needed, as the mouse would leave the window and turning would stop.  That's the reason I'm looking for a way to do this, because I'm doing something similar.

I'm not sure if the Robot class will do what I'm looking to do; it seems sort of hackish to keep repositioning the cursor inside the window when it tries to leave, I'm not sure if I'll be able to do that without having the cursor constantly appear to be trying to escape the window borders.  I have to look into it though.  Thank you for the suggestion.
Page Index Toggle Pages: 1