# Problem with robot cursor

**URL:** <https://discourse.processing.org/t/problem-with-robot-cursor/2046>\
**Category:** Coding Questions\
**Created:** [July 24, 2018, 1:34pm UTC](https://discourse.processing.org/t/problem-with-robot-cursor/2046 "2018-07-24T13:34:53Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![erwrow](https://avatars.discourse-cdn.com/v4/letter/e/b782af/32.png) [@erwrow](https://discourse.processing.org/u/erwrow)\
**Post date:** [July 24, 2018, 1:51pm UTC](https://discourse.processing.org/t/problem-with-robot-cursor/2046/2 "2018-07-24T13:51:41Z")

</div>

i’ve reached the problem, i was using the middle position of the mouseX (97) instead of the middle position of the mouseY, those values are for my screen, so it wont work in to many displays, i’ll implement an more responsive coding. Thanks if you stopped to watch the post!

The correct code is the following:

```auto
import java.awt.*;
import java.awt.event.*;

Robot robot;

float x, y, z;
int xp = 0, yp = 0, zp = 0, mouseYmiddle = 0, mouseXmiddle = 0;
boolean flag = true;

void setup()
{
  size(200,200,P3D);
  surface.setLocation((displayWidth / 2) - (width / 2), (displayHeight / 2) - (height / 2));
  try
  { 
    robot = new Robot();
    robot.setAutoDelay(0);
  }
  catch(Exception e)
  {
    println(e);
  }
  x = 100;
  y = 100;
  z = 0;
  noCursor();
}

void draw()
{
  robot.mouseMove(displayWidth / 2, displayHeight / 2);
  background(180);
  fill(255);
  translate(100, 100, 0);
  box(40, 40, 40);
  fill(0);
  line(0, 0, 0, 50, 0, 0);
  text("X", 50, 0, 0);
  line(0, 0, 0, 0, 50, 0);
  text("Y", 0, 50, 0);
  line(0, 0, 0, 0, 0, 50);
  text("Z", 0, 0, 50);
  camera(xp, yp, zp, x, y, z, -1, -1, -1);
  if(keyPressed)
  {
    if(key == 'w')
    {
      xp = (xp>200)?200:(xp+1);
      x++;
    }
    if(key == 's')
    {
      xp = (xp<0)?0:(xp-1);
      x--;
    }
    if(key == 'd')
    {
      yp = (yp>200)?200:(yp+1);
      y++;
    }
    if(key == 'a')
    {
      yp = (yp<0)?0:(yp-1);
      y--;
    }
  }
  if(mouseY > mouseYmiddle + 1)
  {
    z += mouseY - mouseYmiddle;
    z = z>100?100:z;
  }
  else if(mouseY < mouseYmiddle - 1)
  {
    z += mouseY - mouseYmiddle;
    z = z<0?0:z;
  }
  if(mouseX > pmouseX)
  {
    
  }
}

void mouseMoved()
{
  if(flag)
  {
    mouseYmiddle = mouseY;
    mouseXmiddle = mouseX;
    flag = false;
  }
}

```

---

_[View the full topic](https://discourse.processing.org/t/problem-with-robot-cursor/2046)._
