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

# CGPostKeyboardEvent(_:_:_:)

Synthesizes a low-level keyboard event on the local machine.

```
func CGPostKeyboardEvent(_ keyChar: CGCharCode, _ virtualKey: CGKeyCode, _ keyDown: boolean_t) -> CGError
```

## Parameters

`keyChar`

The value of the character to generate, or 0 to specify that the system should guess an appropriate value based on the default key mapping.

`virtualKey`

The virtual key code for the event. See [`CGKeyCode`](/documentation/CoreGraphics/CGKeyCode).

`keyDown`

Pass `true` to specify that the key position is down; otherwise, pass `false`.

## Return Value

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

## Discussion

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(keyboardEventSource:virtualKey:keyDown:)`](/documentation/CoreGraphics/CGEvent/init(keyboardEventSource:virtualKey:keyDown:)), which allows you to create a keyboard 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)