# mouseX and mouseY not updating even when mouse is still in window

**URL:** <https://discourse.processing.org/t/mousex-and-mousey-not-updating-even-when-mouse-is-still-in-window/42588>\
**Category:** Coding Questions\
**Created:** [August 13, 2023, 10:29am UTC](https://discourse.processing.org/t/mousex-and-mousey-not-updating-even-when-mouse-is-still-in-window/42588 "2023-08-13T10:29:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![blaster003](https://avatars.discourse-cdn.com/v4/letter/b/3d9bf3/32.png) [@blaster003](https://discourse.processing.org/u/blaster003)\
**Post date:** [August 13, 2023, 10:29am UTC](https://discourse.processing.org/t/mousex-and-mousey-not-updating-even-when-mouse-is-still-in-window/42588/1 "2023-08-13T10:29:01Z")

</div>

I’ve been making an [arras.io](http://arras.io) (a top down shooter) type game, and I’m trying to make the player (which is in the centre)'s cannon(s) face the cursor, using `atan2()` and the `rotate()` function. It does work as expected, but sometimes the cannon just freezes and doesn’t move at all, sometimes resolving itself and continuing as normal, or just staying there. This is mostly random and I don’t have a clue as to what causes it.

```auto
void setup() {
	fullScreen();
}

void draw() {
	fullScreen();

	pushMatrix();

	strokeWeight(5);

	translate(width/2, height/2);
	render(atan2((mouseY - height / 2), (mouseX - width / 2)));

	popMatrix();
}

void render(float _rot) {
	pushMatrix();

	rotate(_rot);

	fill(160);
	stroke(lerpColor(160, color(0), 0.1));

	beginShape();
	vertex(0, -5);
	vertex(20, -5);
	vertex(20, 5);
	vertex(0, 5);
	endShape(CLOSE);

	popMatrix();
}

```

I’m making this sketch in OpenProcessing. I know that mouseX and mouseY don’t update when the cursor is off the window, but when this happens the mouse has been in the window the whole time the sketch was being run.

Is this just a Processing thing? Or is this possible to fix? Please let me know.

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [August 13, 2023, 12:32pm UTC](https://discourse.processing.org/t/mousex-and-mousey-not-updating-even-when-mouse-is-still-in-window/42588/2 "2023-08-13T12:32:27Z")

</div>

I tried your code in Processing IDE and it worked fine. Just a copy of points

1. Remove the `fullScreen();` from the draw() method as it is not needed and shouldn’t be there
2. Add a background statement at the beginning of draw to erase previous cannon positions.

> [@blaster003](#):
>
> but when this happens the mouse has been in the window the whole time the sketch was being run.

Mouse events are sent to the _active application_ if you click the mouse outside OpenProcessing window then your sketch will not respond to the mouse even if the mouse cursor is over your sketch window.
