How can I capture the mouse in window mode?

Hi!

How can I capture the mouse such that it can’t leave the window as long as it’s active/focused? Also is this possible to achieve in the editor as well?

All things related to window and input you can find in FViewport

https://docs.unrealengine.com/latest/INT/API/RuntimeModules/Engine/FViewport/index.html

And there you can find things like that :slight_smile: :

https://docs.unrealengine.com/latest/INT/API/RuntimeModules/Engine/FViewport/LockMouseToViewport/index.html

To get instace of your viewport from:

GEngine->GameViewport

It really looks like that would solve it. However when I try, it has no effect. I guess I will have to search through the StrategyGame example. It looks like they have used Slate in some way to prevent that the mouse leaves the window but am not quite sure yet.

I’m also in the same boat. I’ve used that function, and nothing changes. The mouse is still free to leave the window. Not a good thing, as the player is supposed to move the camera by moving the cursor to the edge of the screen.

Edit: After reading through this post, I’ve found that mouse locking works only after going fullscreen with alt + enter. After going fullscreen, the mouse is still locked even after leaving fullscreen. Why wouldn’t it just work on launch?

I think I will submit this as a bug since either the name of the method is incorrect or the method isn’t working. Thanks for letting me know.

I added a bug report here link. Hope we can get some help with this.