Mouse events outside window

From Processing

Jump to: navigation, search
Versions: 1.0+
Contributors: seltar
Started: 2006-03-19


Run this at the beginning of draw() and you'll get coordinates outside of the frame even when the mouse isn't clicked.

Source Code

/**
clickedmousepos taken from http://wiki.processing.org/index.php/Mouse_events_outside_window
@author Yonas Sandbæk
*/
 
void setMouseXY() 
{
  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;
  }
  mouseX = mouse.x-winloc.x;
  mouseY = mouse.y-winloc.y;
}

Downloads

Related Links

Personal tools