<!--
{
  "availability" : [
    "macCatalyst: 13.1.0 - 13.1.0",
    "macOS: 10.0.0 - 10.6.0"
  ],
  "documentType" : "symbol",
  "framework" : "CoreGraphics",
  "identifier" : "/documentation/CoreGraphics/CGPostMouseEvent",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Core Graphics"
    ],
    "preciseIdentifier" : "c:@F@CGPostMouseEvent"
  },
  "title" : "CGPostMouseEvent"
}
-->

# CGPostMouseEvent

Synthesizes a low-level mouse-button event on the local machine.

```
extern CGError CGPostMouseEvent(CGPoint mouseCursorPosition, boolean_t updateMouseCursorPosition, CGButtonCount buttonCount, boolean_t mouseButtonDown, ...);
```

## Discussion

### Parameters

- mouseCursorPosition: The new coordinates of the mouse in global display space.
- updateMouseCursorPosition: Pass `true` if the on-screen cursor should be moved to the location specified in the `mouseCursorPosition` parameter; otherwise, pass `false`.
- buttonCount: The number of mouse buttons, up to a maximum of 32.
- mouseButtonDown: Pass `true` to specify that the primary or left mouse button is down; otherwise, pass `false`.
- …: Zero or more Boolean values that specify whether the remaining mouse buttons are down (`true`) or up (`false`). The second value, if any, should specify the state of the secondary mouse button (right). A third value would specify the state of the center button, and the remaining buttons would be in USB device order.

### Returns

A result code. See the result codes described in [Quartz Display Services](/documentation/CoreGraphics/quartz-display-services).

## Discussion

Based on the arguments you pass to this function, the function generates the appropriate mouse-down, mouse-up, mouse-move, or mouse-drag events by comparing the new state with the current state.

This function is not recommended for general use because of undocumented special cases and undesirable side effects. The recommended replacement for this function is [`init(mouseEventSource:mouseType:mouseCursorPosition:mouseButton:)`](/documentation/CoreGraphics/CGEvent/init(mouseEventSource:mouseType:mouseCursorPosition:mouseButton:)), which allows you to create a mouse event and customize the event before posting it to the event system.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)