# Locking cursor to window without hiding it?

**URL:** <https://discourse.glfw.org/t/locking-cursor-to-window-without-hiding-it/869>\
**Category:** support\
**Created:** [March 4, 2017, 5:59pm UTC](https://discourse.glfw.org/t/locking-cursor-to-window-without-hiding-it/869 "2017-03-04T17:59:09Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [March 6, 2017, 10:22am UTC](https://discourse.glfw.org/t/locking-cursor-to-window-without-hiding-it/869/2 "2017-03-06T10:22:50Z")

</div>

I think there might be two separate issues here.

One is that your camera goes wild when you tab out of the window, the other is that you want a method to constrain the cursor to the window without hiding it.

To constrain the cursor you could disable the cursor and draw your own - this is the approach used by most games, see [this post](http://discourse.glfw.org/t/crosshair-cursor-isnt-smooth/859/3?u=dougbinks) on some approaches to drawing your own cursor.

Another approach might be to constrain the cursor by calling [glfwSetCursorPos](http://www.glfw.org/docs/latest/group__input.html#ga04b03af936d906ca123c8f4ee08b39e7) when it reaches the outer edge to keep it inside, though there are likely a few problems in getting this to work well.

Neither of these will help with ALT+TAB issues, as the window looses focus then. You’ll need to handle this by not updating the first person camera with mouse deltas when the window is loosing/gaining focus and also beware that minimizing the window causes a window size message of 0 width and height (which can also cause your camera to go crazy if you process these for control).

---

_[View the full topic](https://discourse.glfw.org/t/locking-cursor-to-window-without-hiding-it/869)._
