How can I lock the cursor to the inside of a window on Mac OS X?
Asked Answered
D

1

11

I'm trying to put together a game for Mac OS X which involves a lot of fast action and flinging around of the mouse cursor. If the user wants to play in windowed mode, I'd quite like to lock the cursor to the inside of the window to avoid accidentally changing programs in the heat of battle (obviously this will cancel itself if the user changes programs or hits escape for the pause menu.)

On Windows, this can be accomplished easily with ClipCursor(). I can't find an equivalent on Mac OS X. Is there one?

Dannica answered 10/1, 2011 at 0:49 Comment(1)
See very similar question SO 4642867 asking the same question for Linux.Braw
H
8

Have a look at CGWarpMouseCursorPosition, CGAssociateMouseAndMouseCursorPosition and CGGetLastMouseDelta (part of ApplicationServices).

See http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/Quartz_Services_Ref/Reference/reference.html

Hurtado answered 10/1, 2011 at 2:55 Comment(2)
While this looks really, really promising, I'm having some horrible cursor refresh rate issues. SetMouseCoalescingEnabled has been unhelpful. I'll be working on this more, and if I figure out what's going on I'll post, but at the moment I can't come up with anything usable with these functions.Dannica
Did you ever figure this out? Having the same issue now while playing games in windowed mode on mac.Waterfall

© 2022 - 2024 — McMap. All rights reserved.