<!--
{
  "availability" : [
    "macCatalyst: 13.1.0 -",
    "macOS: 10.4.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreGraphics",
  "identifier" : "/documentation/CoreGraphics/CGEventSource/init(stateID:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Core Graphics",
      "CoreGraphics"
    ],
    "preciseIdentifier" : "c:@F@CGEventSourceCreate"
  },
  "title" : "init(stateID:)"
}
-->

# init(stateID:)

Returns a Quartz event source created with a specified source state.

```
init?(stateID: CGEventSourceStateID)
```

## Parameters

`stateID`

The event state table to use for this event source. Pass one of the constants listed in [`CGEventSourceStateID`](/documentation/CoreGraphics/CGEventSourceStateID).

## Return Value

A new event source, or `NULL` if the specified source state is not valid. When you no longer need the event source, you should release it using the function `CFRelease`.

## Discussion

If two or more event sources are using the same source state and one of them is released, the remaining event sources will behave as if all keys and buttons on input devices are up in generating new events from this source.

---

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)