Connects or disconnects the mouse and cursor while an application is in the foreground.


func CGAssociateMouseAndMouseCursorPosition(_ connected: boolean_t) -> CGError



Pass true if the mouse and cursor should be connected; otherwise, pass false.

Return Value

A result code. See Core Graphics Data Types and Constants.


When you call this function to disconnect the cursor and mouse, all events received by your application have a constant absolute location but contain mouse delta (change in X and Y) data. You may hide the cursor or change it into something appropriate for your application. You can reposition the cursor by using the function CGDisplayMoveCursorToPoint(_:_:) or the function CGWarpMouseCursorPosition(_:).

See Also

Controlling the Mouse Cursor

func CGDisplayHideCursor(CGDirectDisplayID) -> CGError

Hides the mouse cursor, and increments the hide cursor count.

func CGDisplayShowCursor(CGDirectDisplayID) -> CGError

Decrements the hide cursor count, and shows the mouse cursor if the count is 0.

func CGDisplayMoveCursorToPoint(CGDirectDisplayID, CGPoint) -> CGError

Moves the mouse cursor to a specified point relative to the display origin (the upper-left corner of the display).

func CGCursorIsVisible() -> boolean_t

Returns a Boolean value indicating whether the mouse cursor is visible.

func CGCursorIsDrawnInFramebuffer() -> boolean_t

Returns a Boolean value indicating whether the mouse cursor is drawn in framebuffer memory.

func CGWarpMouseCursorPosition(CGPoint) -> CGError

Moves the mouse cursor without generating events.

func CGGetLastMouseDelta() -> (x: Int32, y: Int32)

Reports the change in mouse position since the last mouse movement event received by the application.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software