When you use full-screen mode, you may want to hide the pointer, programatically move the pointer, or disassociate mouse movement from pointer position. To hide or show the pointer, use the functions CGDisplayHideCursor and CGDisplayShowCursor. These functions control the pointer visibility on all displays.
Quartz Display Services provides a convenient function for disassociating mouse movement from pointer position while an application is in the foreground. By passing false to the function CGAssociateMouseAndMouseCursorPosition, you can prevent mouse movement from changing the pointer position. Pass true to reverse the effect. You should also hide the menu bar because clicking it can cause the pointer to become visible again, even after capturing the display.
You can move the pointer programatically by calling the function CGDisplayMoveCursorToPoint. This function takes two parameters, a display ID and a point. The location of the point is relative to the display origin (the upper-left corner of the display).
Listing C-5 shows how you would hide and move the cursor on the main display, disassociate the cursor from mouse movement, and restore the cursor and mouse when you are done.
Listing C-5 Controlling the pointer programmatically
CGDisplayHideCursor (kCGDirectMainDisplay); //Hide cursor |
CGDisplayMoveCursorToPoint (kCGDirectMainDisplay,CGPointZero); //Place at display origin |
CGAssociateMouseAndMouseCursorPosition (FALSE); |
// Perform your application's main loop. |
//In the mouse movement notification function, get the motion deltas |
CGAssociateMouseAndMouseCursorPosition (TRUE); |
CGDisplayShowCursor (kCGDirectMainDisplay); |
Last updated: 2008-06-09