I'm developing a game in Cocoa
, and I want to rotate the camera when the user moves the mouse, and the screen is limiting the camera movement. I hid the mouse cursor, but I want to listen when the physical mouse moves, not when the mouse cursor moves. I've heard about IOKit
but that seems to be too low level. If it is any high-level way to do that, then how? And else, how do I use IOKit
.
1
votes
1 Answers
2
votes
When you hide the cursor, call CGAssociateMouseAndMouseCursorPosition(FALSE)
. That will make it so that mouse movement does not move the cursor.
You will continue to get NSEventTypeMouseMoved
, NSEventTypeLeftMouseDragged
, NSEventTypeRightMouseDragged
, and NSEventTypeOtherMouseDragged
events as the mouse is moved (depending on whether buttons are pressed during the move). Because the cursor isn't moving, the locationInWindow
won't be meaningful. It will continue to report the last location from when you disassociated the cursor from the mouse. However, the deltaX
and deltaY
properties will indicate how far and in what direction the mouse moved.