PrintWriter pw;

void setup()
{
  size( 500, 500 );
  pw = createWriter( "output.txt" );
}

void draw()
{
  pw.println( "x: " + mouseX + ", y: " + mouseY );
}

void keyPressed()
{
  if( key == ' ' ) {
    pw.flush();
    pw.close();
    exit();
  }
}