Locking mouse to window

Hello,

Does anyone know how to lock the mouse inside a non-fullscreen Panda3D window? i.e. so the user can’t move it outside unless I unlock it.

Thanks.

Welcome to the forums!

wp = WindowProperties()
wp.setMouseMode(WindowProperties.MRelative)
base.requestProperties(wp)

This will work on all platforms, with the sole exception of Windows. On Windows, just reposition the mouse cursor into the middle of the window every frame.

Thanks rdb

Actually, this will not work on OSX Lion the way you expect it too. I have tried this and currently use this method in my program with semi-success on OSX Lion. When you click the mouse, your cursor will move in random places and stop listening for mouse movement. I don’t know why but it does. I’m not the only person with this issue on OSX either. I have concluded that for now, I’m only going to target the Windows platform.

That’s not supposed to happen- please file a bug report, if one isn’t already there.

I don’t believe it’s a bug on Pandas part I just believe its the way OSX handles mouse events and such. When I click the mouse (right or left), track pad or blutooth mouse, it creates sporadic mouse coordinates even if the mouse doesn’t move. When this happens, it’s as if Panda thinks the mouse has left the window and it has lost focus. However, the setP() still works (meaning the mouse still detects movement along the X-axis but not the Y-axis. I can post a video showing this if anyone wants to have a look see!

–Edit–
I can also share my code as well!

Here is the LINK that I originally was speaking of. The person also has problems within OSX but NOT in any other OS. I don’t know if this is a MAbsolute/MRelative problem but his symptoms are the same as mine in that if I comply with the requirements of base.win and use MAbsolute/MRelative, the same thing happens with the mouse tracking.