# 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:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimjamjack](https://avatars.discourse-cdn.com/v4/letter/j/e495f1/32.png) [@jimjamjack](https://discourse.glfw.org/u/jimjamjack)\
**Post date:** [March 4, 2017, 5:59pm UTC](https://discourse.glfw.org/t/locking-cursor-to-window-without-hiding-it/869/1 "2017-03-04T17:59:09Z")

</div>

When I tab out of my GLFW window, my first person camera flies around all over the place. I know you can stop this with glfwSetInputMode(window, GLFW\_CURSOR, GLFW\_CURSOR\_DISABLED); but that means that I can no longer see my crosshair cursor (which I need). Can I lock the cursor to the screen without hiding it?

---

<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).

---

<div class="post-metadata">

**Author:** ![jimjamjack](https://avatars.discourse-cdn.com/v4/letter/j/e495f1/32.png) [@jimjamjack](https://discourse.glfw.org/u/jimjamjack)\
**Post date:** [March 6, 2017, 5:23pm UTC](https://discourse.glfw.org/t/locking-cursor-to-window-without-hiding-it/869/3 "2017-03-06T17:23:41Z")

</div>

Using glfwSetInputMode(window, GLFW\_CURSOR, GLFW\_CURSOR\_DISABLED); stops the issue, even when tabbing out, so I think your first reply is probably the best option. It’s just that the side effect is no longer being able to see the crosshair.

I thought maybe there was a way to disable the cursor, but still show GLFW’s given crosshair cursor, or maybe a separate method that only locks the cursor and doesn’t hide it.

Appreciate the help though.
