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 Coords outside frame
Page Index Toggle Pages: 1
Mouse Coords outside frame (Read 594 times)
Mouse Coords outside frame
Apr 30th, 2010, 4:58am
 
Hi, I've been using processing for a couple of years, and usually I've been able to find an answer to questions I have, but this particular one has got me absolutely stumped.

I'm writing a mouse-tracking program which converts mouse movement into something more visually pleasing. However I want to be able to minimse the program and have it continue to track mouse coords even when the frame doesn't have focus.

Is this possible in Processing?

Thanks.

P.s. Sorry if this doesn't quite qualify as a syntax question but I couldn't work out where it best fitted.
Re: Mouse Coords outside frame
Reply #1 - Apr 30th, 2010, 5:25am
 
I asked this same question and found a work around in this post
http://processing.org/discourse/yabb2/num_1263445642.html

I modified it a little. It works best with the frame set to undecorated

Quote:
int mX, mY;
public int cnt;
public PImage a;

public Robot robot;
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 += 0;//3
//    winloc.y += 32;//29
//  }
  mX = mouse.x-winloc.x-1;
  mY = mouse.y-winloc.y-1;
//  mX = mouse.x;
// mY = mouse.y;
}

public void init() {
  /// to make a frame not displayable, you can
  // use frame.removeNotify()
  frame.removeNotify(); 
 
  frame.setUndecorated(true);
 
  // addNotify, here i am not sure if you have  
  // to add notify again.  
  frame.addNotify(); 
  super.init();
}

//RoboMouse robo; 
//Bot bot;



void setup(){
  
 size(255,255,P3D);
}

public int mode = 2;
void draw(){
  
   try {
      robot = new Robot();
    } 
    catch (AWTException e) {
      e.printStackTrace(); 
    }
    

  setMouseXY();
  background(1);
  stroke(255);

  line(mX, 0, mX, height);
   stroke(233,23,23);
  line(mouseX, 0, mouseX, height);
  stroke(-1);
  line(0, mY, width, mY);
  stroke(233,23,23);
  line(0, mouseY, width, mouseY);
 
  println( "mX is " + mX + " and mY is " + mouseY );
  
}


Page Index Toggle Pages: 1