<!--
{
  "availability" : [
    "macCatalyst: -",
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreGraphics",
  "identifier" : "/documentation/CoreGraphics/CGEventSource",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Core Graphics"
    ],
    "preciseIdentifier" : "c:@T@CGEventSourceRef"
  },
  "title" : "CGEventSource"
}
-->

# CGEventSource

Defines an opaque type that represents the source of a Quartz event.

```
class CGEventSource
```

## Overview

A Quartz event source is an object that contains accumulated state related to event generation and event posting. Every event source has an associated global event state table called a source state. When you call [`init(stateID:)`](/documentation/CoreGraphics/CGEventSource/init(stateID:)) to create an event source, you specify which source state to use. For more information about source states, see [`CGEventSourceStateID`](/documentation/CoreGraphics/CGEventSourceStateID).

A typical use of an event source would be to obtain the source from a Quartz event received by an event tap callback function, and then to use that source for any new events created as a result of the received event. This has the effect of marking the events as being related.

This opaque type is derived from CFType and inherits the properties that all Core Foundation types have in common. For more information, see <doc://com.apple.documentation/documentation/CoreFoundation/CFTypeRef>.

## Topics

### Initializers

[`init(event:)`](/documentation/CoreGraphics/CGEventSource/init(event:))

Returns a Quartz event source created from an existing Quartz event.

[`init(stateID:)`](/documentation/CoreGraphics/CGEventSource/init(stateID:))

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

### Instance Properties

[`keyboardType`](/documentation/CoreGraphics/CGEventSource/keyboardType)

Returns the keyboard type to be used with a Quartz event source.

[`localEventsSuppressionInterval`](/documentation/CoreGraphics/CGEventSource/localEventsSuppressionInterval)

Returns the interval that local hardware events may be suppressed following the posting of a Quartz event.

[`pixelsPerLine`](/documentation/CoreGraphics/CGEventSource/pixelsPerLine)

Gets the scale of pixels per line in a scrolling event source.

[`sourceStateID`](/documentation/CoreGraphics/CGEventSource/sourceStateID)

Returns the source state associated with a Quartz event source.

[`userData`](/documentation/CoreGraphics/CGEventSource/userData)

Returns the 64-bit user-specified data for a Quartz event source.

### Type Properties

[`typeID`](/documentation/CoreGraphics/CGEventSource/typeID)

Returns the type identifier for the opaque type `CGEventSourceRef`.

### Instance Methods

[`getLocalEventsFilterDuringSuppressionState(_:)`](/documentation/CoreGraphics/CGEventSource/getLocalEventsFilterDuringSuppressionState(_:))

Returns the mask that indicates which classes of local hardware events are enabled during event suppression.

[`setLocalEventsFilterDuringSuppressionState(_:state:)`](/documentation/CoreGraphics/CGEventSource/setLocalEventsFilterDuringSuppressionState(_:state:))

Sets the mask that indicates which classes of local hardware events are enabled during event suppression.

### Type Methods

[`buttonState(_:button:)`](/documentation/CoreGraphics/CGEventSource/buttonState(_:button:))

Returns a Boolean value indicating the current button state of a Quartz event source.

[`counterForEventType(_:eventType:)`](/documentation/CoreGraphics/CGEventSource/counterForEventType(_:eventType:))

Returns a count of events of a given type seen since the window server started.

[`flagsState(_:)`](/documentation/CoreGraphics/CGEventSource/flagsState(_:))

Returns the current flags of a Quartz event source.

[`keyState(_:key:)`](/documentation/CoreGraphics/CGEventSource/keyState(_:key:))

Returns a Boolean value indicating the current keyboard state of a Quartz event source.

[`secondsSinceLastEventType(_:eventType:)`](/documentation/CoreGraphics/CGEventSource/secondsSinceLastEventType(_:eventType:))

Returns the elapsed time since the last event for a Quartz event 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)