Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Controlling the Pointer

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);


< Previous PageNext Page > Hide TOC


Last updated: 2008-06-09




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice