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 › capture endless mouse movement
Page Index Toggle Pages: 1
capture endless mouse movement (Read 2454 times)
capture endless mouse movement
Jan 13th, 2010, 9:07pm
 
hello,

i am using a mouse as a sensor for a program.
the problem is, that i am using the mouse to capture the speed of a movement that always goes in the same direction. so as soon as  the mouse reaches the end of my screen i only get ZERO.  Cheesy
how can i get over this border?
i know that it is possible, because in some games and programs the mouse is used like that. (for example in every first person shooter)

i am happy about any kind of help!

Re: capture endless mouse movement
Reply #1 - Jan 14th, 2010, 12:40am
 
Post some code. It'll help us better help you.

There was a hack for getting mouseX and mouseY even when the mouse was outside the frame of the window (http://processing.org/hacks/hacks:clickedmousepos), BUT I just tried it and it doesn't seem to work for me anymore! See:

Quote:
int mX, mY;

void setMouseXY()
{
  mX = mouseX; mY = mouseY;
  if(mouseX>=0 && mouseX<width && mouseY>=0 && mouseY<height) return;
  Point mouse, winloc;
  mouse = MouseInfo.getPointerInfo().getLocation();
  winloc = frame.getLocation();
  if(!frame.isUndecorated()){
    winloc.x += 3;
    winloc.y += 29;
  }
  mX = mouse.x-winloc.x;
  mY = mouse.y-winloc.y;
}

void draw(){
  setMouseXY();
  background(0);
  stroke(255);
  line(mX, 0, mX, height);
  line(0, mY, width, mY);
  println( "mX is " + mX + " and mY is " + mouseY );
}



You might be out of luck. Cry
Re: capture endless mouse movement
Reply #2 - Jan 14th, 2010, 1:15am
 
dash_snow, most games are full screen anyway, so mouse is always on the game area...

The hack is... hackish! Smiley
The name of the function is misleading (should have been getXY() for example), it modifies Processing's internal variables which should be read-only, and it hard-codes the size of the frame of the sketch's window, instead of using insets...
But the root, using MouseInfo.getPointerInfo().getLocation(), is good.

TfGuy44, you addressed the middle point (not changing mouseX/Y) but then you should no longer rely on these values: just remove the first two lines of the function, it will work...
Re: capture endless mouse movement
Reply #3 - Jan 14th, 2010, 1:22am
 
PhilHo - that certainly improves TfGuy44's posted code, which only returned the mouse position over the sketch window, but I'm not sure if it solves dash_snow's problem: when you reach the end of the screen (as in monitor screen) it stops registering mouse motion in that direction... and I'm guessing this is actually what's meant.

I suspect this might be a tricky one - presumably you'd have to go more low level than simple mouse events and somehow get raw data from the mouse?
Re: capture endless mouse movement
Reply #4 - Jan 14th, 2010, 2:03am
 
Ah, you mean the cursor no longer moves but the user continues to move the device, so the coder expects to still get movement information from the device even if the coordinates of the cursor on screen is stable?

I don't even know if it is possible with standard API (even at system level), unless, perhaps, with a special mouse driver? Might be even harder with Java... Now, I might just ignore how to do it. Wink
Re: capture endless mouse movement
Reply #5 - Jan 14th, 2010, 2:12am
 
Perhaps the answer is simply to move the actual mouse position back to a point that can be registered  So when it reaches the edge of the screen keep a record of the current value, set the mouse position back to the opposite edge of the screen and use the current mouse position + the recorded value as the value passed to the programme.

Now that's obviously a hypothetical and untested solution.  IIRC you can use Robot to set the mouse position in this way.

Failing that I'd be tempted to hook the mouse sensor up to an Arduino: then you have hardware level access to the sensor and can do what you want with the readings Smiley
Re: capture endless mouse movement
Reply #6 - Jan 14th, 2010, 2:04pm
 
hey, thanks for the replies.

Yes, i need the mouse value not only outside the window, but also outside the screen.
i think the idea to move the mouse with Robot is a good! i am going to try that now.
to use an arduino is what i am normally doing, but this time need the data very fast in processing, in order to send data to an arduino board. and i have very bad experience with sending and receiving data from processing to arduino in the same time  

thank!
Re: capture endless mouse movement
Reply #7 - Apr 29th, 2010, 10:33am
 
This works!!! Thanks a lot!!

Code:

int mX, mY;

void setMouseXY()
{
 mX = mouseX; mY = mouseY;
// if(mouseX>=0 && mouseX<width && mouseY>=0 && mouseY<height) return;
 Point mouse, winloc;
 mouse = MouseInfo.getPointerInfo().getLocation();
 winloc = frame.getLocation();
 if(!frame.isUndecorated()){
   winloc.x += 3;
   winloc.y += 29;
 }
 mX = mouse.x-winloc.x;
 mY = mouse.y-winloc.y;
}

void draw(){
 setMouseXY();
 background(0);
 stroke(255);
 line(mX, 0, mX, height);
 line(0, mY, width, mY);
 println( "mX is " + mX + " and mY is " + mouseY );
}
Page Index Toggle Pages: 1