<!--
{
  "availability" : [
    "macOS: 10.5.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSEvent/init(cgEvent:)-4igjn",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSEvent(cm)eventWithCGEvent:"
  },
  "title" : "init(cgEvent:)"
}
-->

# init(cgEvent:)

Creates and returns an event object for a Core Graphics event.

```
init?(cgEvent: CGEvent)
```

## Parameters

`cgEvent`

A <doc://com.apple.documentation/documentation/CoreGraphics/CGEvent> opaque type that represents an event.

## Return Value

An autoreleased `NSEvent` object that is equivalent to `cgEvent`.

## Discussion

The returned object retains the `CGEventRef` object (`cgEvent`) until it (the Objective-C object) is freed—it then releases the `CGEventRef` object.  If no Cocoa event corresponds to the `CGEventRef` object, this method returns `nil`.

## See Also

[`var cgEvent: CGEvent?`](/documentation/AppKit/NSEvent/cgEvent)

The Core Graphics event object corresponding to this event.



---

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)