# Snapping the mouse to the center of the window?

**URL:** <https://discourse.processing.org/t/snapping-the-mouse-to-the-center-of-the-window/23896>\
**Category:** Coding Questions\
**Created:** [September 16, 2020, 5:36pm UTC](https://discourse.processing.org/t/snapping-the-mouse-to-the-center-of-the-window/23896 "2020-09-16T17:36:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sashakoshka](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@sashakoshka](https://discourse.processing.org/u/sashakoshka)\
**Post date:** [September 16, 2020, 5:36pm UTC](https://discourse.processing.org/t/snapping-the-mouse-to-the-center-of-the-window/23896/1 "2020-09-16T17:36:48Z")

</div>

I am trying to snap the mouse cursor to the center of the window every frame. I tried using the robot class to do this, but the problem with that solution is it positions the cursor relative to the screen, not the window, so it only works in fullscreen.  
Is there a better way to move the cursor to the center of the window, or if not, is there a way to get the x and y position of the window on screen?

P.S. This is for a first person 3D game.

---

<div class="post-metadata">

**Author:** ![Hyperion65](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hyperion65/32/10569_2.png) [@Hyperion65](https://discourse.processing.org/u/Hyperion65)\
**Post date:** [September 18, 2020, 6:47am UTC](https://discourse.processing.org/t/snapping-the-mouse-to-the-center-of-the-window/23896/2 "2020-09-18T06:47:54Z")

</div>

hello, it sounds a little confusing. if you position the mouse in the center every frame it basically means that the mouse becomes unusable to you, no ? in that case, you could ignore mouseX and mouseY as a means of interaction and use noCursor() to hide it.

if you use the mouse as a navigational tool as is usual in FPS games, you might simply not show the cursor (tickling your avatar in the back) and use mouseX to turn him left and right.

however, for your question, maybe this will be interesting to you:

> [@getLocation() of the sketch](https://discourse.processing.org/t/getlocation-of-the-sketch/5763):
>
> I try to catch the location of my sketch, but I don’t find any option to do that like surface.setLocation(). Any idea which method can be used to catch the sketch position, like before getLocationOnScreen()

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [September 18, 2020, 8:36am UTC](https://discourse.processing.org/t/snapping-the-mouse-to-the-center-of-the-window/23896/3 "2020-09-18T08:36:23Z")

</div>

Whenever window recognition, mouse clicks, etc. are necessary, I use [AHK](https://www.autohotkey.com/docs/AutoHotkey.htm) in conjunction. A small background program, especially good for games.
