Snapping the mouse to the center of the window?

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.

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:


Whenever window recognition, mouse clicks, etc. are necessary, I use AHK in conjunction. A small background program, especially good for games.