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 & HelpPrograms › Restricting Mouse Pointer
Page Index Toggle Pages: 1
Restricting Mouse Pointer (Read 985 times)
Restricting Mouse Pointer
Sep 16th, 2007, 1:50am
 
Hi all,
I'm a relatively new Programmer in Processing, and am facing a problem.

The problem is, I want a user to draw something with the help of mouse, but at the same time want to restrict his mouse in some rectangular area in the screen. How can I do that? For example something like,
if(mouseX>400 || mouseY>500) restrictMousePointer();

I've seen that the mouseX and mouseY pointer are values which can not be set, we can only get the value.

Any idea?
Re: Restricting Mouse Pointer
Reply #1 - Sep 16th, 2007, 1:59am
 
You could use the java.awt.Robot class, but be aware you cannot use this in an applet without jumping through a lot of hoops, singing applets, and the like.
Re: Restricting Mouse Pointer
Reply #2 - Sep 16th, 2007, 2:04am
 
How can we use Classes of java in our processing code? (You can just give a link to some thread which has this discussion if it'll take a lot of time of yours... it must have been discussed somewhere)

Also, is there no easy way?
Re: Restricting Mouse Pointer
Reply #3 - Sep 16th, 2007, 2:27am
 
Processing is Java, you can use any (1.4 or earlier) Java directly within processing.

you just add "import <java pacakge>;" to the top (in this case: "import java.awt.*;" and you can use it.

See http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Robot.html for detaisl about the Robot.

There is no easy way, as you could do nasty things if you can control the mouse, e.g. lock it to a single point and never let it move.
Re: Restricting Mouse Pointer
Reply #4 - Sep 16th, 2007, 5:45pm
 
thanks !! that works great! But the only problem is, mouseX and mouseY return coordinates w.r.t the current window while mouseMove of the Robot class takes them in absolute screen coodinates.
Just one more help - can you tell me the class/method by which I can know my client windows coordinates , so that i can do something meaningful?

Thanks !!
Re: Restricting Mouse Pointer
Reply #5 - Sep 16th, 2007, 6:13pm
 
The following code will show the top left corner's on screen location. Unfortunately it includes the title-bar height-width but that should be constant.

Code:
void setup()
{
size(200,200);
}

void draw()
{
if(frameCount>2) //Will throw an exception if you try before frame 2
{
Point p=frame.getLocationOnScreen();
println("location: "+p.x+","+p.y);
}
}
Re: Restricting Mouse Pointer
Reply #6 - Sep 16th, 2007, 6:16pm
 
thanks a lot !!
Page Index Toggle Pages: 1