# Moving a cursor with Robot makes it skip across the window?

**URL:** <https://discourse.processing.org/t/moving-a-cursor-with-robot-makes-it-skip-across-the-window/23373>\
**Category:** Coding Questions\
**Created:** [August 20, 2020, 1:04am UTC](https://discourse.processing.org/t/moving-a-cursor-with-robot-makes-it-skip-across-the-window/23373 "2020-08-20T01:04:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![CosmicCrowMC](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@CosmicCrowMC](https://discourse.processing.org/u/CosmicCrowMC)\
**Post date:** [August 20, 2020, 1:04am UTC](https://discourse.processing.org/t/moving-a-cursor-with-robot-makes-it-skip-across-the-window/23373/1 "2020-08-20T01:04:08Z")

</div>

So, I’ve been working on a 3d game for quite a while now. It’s first-person, and you look around by moving the mouse - makes sense. I’ve sent the game to some friends to playtest, and it works fine for all but one of them. For one of them, any time they’re in a portion of the game that has a script to move the cursor manually with Robot, their mouse will instead skip to the edge of the window, preventing it from ever being on the actual window. Any time the cursor is not controlled, however, their mouse CAN be placed on the window. Because only they are having the problem, I’m thinking they have some sort of antivirus on their computer that’s messing with the program, but I haven’t been able to find any solutions both online and with them sharing their screen with me. Does anyone know what could be causing this?

I’ll post my code here:

```auto
if(surface instanceof processing.opengl.PSurfaceJOGL){
    com.jogamp.newt.opengl.GLWindow window = (com.jogamp.newt.opengl.GLWindow)(((PSurfaceJOGL)surface).getNative());
    com.jogamp.nativewindow.util.Point point = window.getLocationOnScreen(new com.jogamp.nativewindow.util.Point());
    if (phase=="Play"&&pause==false) {
      robot.mouseMove(point.getX()+width/2,point.getY()+height/2);
    }
  }

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [August 20, 2020, 5:42am UTC](https://discourse.processing.org/t/moving-a-cursor-with-robot-makes-it-skip-across-the-window/23373/2 "2020-08-20T05:42:13Z")

</div>

> [@CosmicCrowMC](#):
>
> `if (phase=="Play"&&pause==false) {`

> **[equals() / Reference](https://processing.org/reference/String_equals_.html)**
>
> Compares two strings to see if they are the same. This method is necessary because it's not possible to compare strings using the equality operator (==). Returns true if the strings are the sam…

`if (!pause && "Play".equals(phase)) {`

---

<div class="post-metadata">

**Author:** ![CosmicCrowMC](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@CosmicCrowMC](https://discourse.processing.org/u/CosmicCrowMC)\
**Post date:** [August 20, 2020, 3:51pm UTC](https://discourse.processing.org/t/moving-a-cursor-with-robot-makes-it-skip-across-the-window/23373/3 "2020-08-20T15:51:32Z")

</div>

I appreciate your interest, however, I don’t see how I format my if-statements would be causing the issue. This is definitely a good thing to keep in mind going forward for comparing strings and booleans, but it does not answer my question.

---

<div class="post-metadata">

**Author:** ![noahbuddy](https://avatars.discourse-cdn.com/v4/letter/n/73ab20/32.png) [@noahbuddy](https://discourse.processing.org/u/noahbuddy)\
**Post date:** [August 21, 2020, 8:43pm UTC](https://discourse.processing.org/t/moving-a-cursor-with-robot-makes-it-skip-across-the-window/23373/4 "2020-08-21T20:43:38Z")

</div>

@CosmicCrowMC The key to @GoToLoop 's answer is the use of the `equals` function when comparing strings.

Unlike some programming languages (Python for example), Processing(Java) will not perform a “contents” comparison on strings when double-equal is used.

Let us know if changing that still does not help.

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [August 22, 2020, 12:12pm UTC](https://discourse.processing.org/t/moving-a-cursor-with-robot-makes-it-skip-across-the-window/23373/5 "2020-08-22T12:12:13Z")

</div>

You might be better not mixing JOGL and AWT’s Robot. GLWindow also has capability to do similar. Possibly some odd interactions going on. See [GLWindow (JOGL, NativeWindow and NEWT APIs)](https://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/newt/opengl/GLWindow.html#warpPointer(int,int))

EDIT : also might want to consider whether it’s a high DPI screen - could be coordinates don’t match up.

> [@noahbuddy](#):
>
> Unlike some programming languages (Python for example), Processing(Java) will not perform a “contents” comparison on strings when double-equal is used.

Yes, this is true and something to watch for. However, if all definitions of `"Play"` are literals in the source code, they will also be object identical, so this shouldn’t be the cause of the bug. Worth fixing still!

---

<div class="post-metadata">

**Author:** ![CosmicCrowMC](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@CosmicCrowMC](https://discourse.processing.org/u/CosmicCrowMC)\
**Post date:** [September 3, 2020, 2:11am UTC](https://discourse.processing.org/t/moving-a-cursor-with-robot-makes-it-skip-across-the-window/23373/6 "2020-09-03T02:11:21Z")

</div>

Works like a charm now! You were right - the two libraries must’ve been messing with each other. Thank you so much!!
