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

# CGEvent

Defines an opaque type that represents a low-level hardware event.

```
class CGEvent
```

## Overview

Low-level hardware events of this type are referred to as Quartz events. A typical event in macOS originates when the user manipulates an input device such as a mouse or a keyboard. The device driver associated with that device, through the I/O Kit, creates a low-level event, puts it in the window server’s event queue, and notifies the window server. The window server creates a Quartz event, annotates the event, and dispatches the event to the appropriate run-loop port of the target process. There the event is picked up by the Carbon Event Manager and forwarded to the event-handling mechanism appropriate to the application environment. You can use event taps to gain access to Quartz events at several different steps in this process.

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

[`copy()`](/documentation/CoreGraphics/CGEvent/copy())

Returns a copy of an existing Quartz event.

[`init(keyboardEventSource:virtualKey:keyDown:)`](/documentation/CoreGraphics/CGEvent/init(keyboardEventSource:virtualKey:keyDown:))

Returns a new Quartz keyboard event.

[`init(mouseEventSource:mouseType:mouseCursorPosition:mouseButton:)`](/documentation/CoreGraphics/CGEvent/init(mouseEventSource:mouseType:mouseCursorPosition:mouseButton:))

Returns a new Quartz mouse event.

[`init(source:)`](/documentation/CoreGraphics/CGEvent/init(source:))

Returns a new Quartz event.

[`init(withDataAllocator:data:)`](/documentation/CoreGraphics/CGEvent/init(withDataAllocator:data:))

Returns a Quartz event created from a flattened data representation of the event.

[`init(scrollWheelEvent2Source:units:wheelCount:wheel1:wheel2:wheel3:)`](/documentation/CoreGraphics/CGEvent/init(scrollWheelEvent2Source:units:wheelCount:wheel1:wheel2:wheel3:))

### Instance Properties

[`flags`](/documentation/CoreGraphics/CGEvent/flags)

Returns the event flags of a Quartz event.

[`location`](/documentation/CoreGraphics/CGEvent/location)

Returns the location of a Quartz mouse event.

[`timestamp`](/documentation/CoreGraphics/CGEvent/timestamp)

Returns the timestamp of a Quartz event.

[`type`](/documentation/CoreGraphics/CGEvent/type)

Returns the event type of a Quartz event (left mouse down, for example).

[`unflippedLocation`](/documentation/CoreGraphics/CGEvent/unflippedLocation)

Returns the location of a Quartz mouse event.

[`data`](/documentation/CoreGraphics/CGEvent/data)

### Type Properties

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

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

### Instance Methods

[`getDoubleValueField(_:)`](/documentation/CoreGraphics/CGEvent/getDoubleValueField(_:))

Returns the floating-point value of a field in a Quartz event.

[`getIntegerValueField(_:)`](/documentation/CoreGraphics/CGEvent/getIntegerValueField(_:))

Returns the integer value of a field in a Quartz event.

[`keyboardGetUnicodeString(maxStringLength:actualStringLength:unicodeString:)`](/documentation/CoreGraphics/CGEvent/keyboardGetUnicodeString(maxStringLength:actualStringLength:unicodeString:))

Returns the Unicode string associated with a Quartz keyboard event.

[`keyboardSetUnicodeString(stringLength:unicodeString:)`](/documentation/CoreGraphics/CGEvent/keyboardSetUnicodeString(stringLength:unicodeString:))

Sets the Unicode string associated with a Quartz keyboard event.

[`post(tap:)`](/documentation/CoreGraphics/CGEvent/post(tap:))

Posts a Quartz event into the event stream at a specified location.

[`postToPSN(processSerialNumber:)`](/documentation/CoreGraphics/CGEvent/postToPSN(processSerialNumber:))

Posts a Quartz event into the event stream for a specific application.

[`postToPid(_:)`](/documentation/CoreGraphics/CGEvent/postToPid(_:))

[`setDoubleValueField(_:value:)`](/documentation/CoreGraphics/CGEvent/setDoubleValueField(_:value:))

Sets the floating-point value of a field in a Quartz event.

[`setIntegerValueField(_:value:)`](/documentation/CoreGraphics/CGEvent/setIntegerValueField(_:value:))

Sets the integer value of a field in a Quartz event.

[`setSource(_:)`](/documentation/CoreGraphics/CGEvent/setSource(_:))

Sets the event source of a Quartz event.

[`tapPostEvent(_:)`](/documentation/CoreGraphics/CGEvent/tapPostEvent(_:))

Posts a Quartz event from an event tap into the event stream.

### Type Methods

[`tapCreate(tap:place:options:eventsOfInterest:callback:userInfo:)`](/documentation/CoreGraphics/CGEvent/tapCreate(tap:place:options:eventsOfInterest:callback:userInfo:))

Creates an event tap.

[`tapCreateForPSN(processSerialNumber:place:options:eventsOfInterest:callback:userInfo:)`](/documentation/CoreGraphics/CGEvent/tapCreateForPSN(processSerialNumber:place:options:eventsOfInterest:callback:userInfo:))

Creates an event tap for a specified process.

[`tapCreateForPid(pid:place:options:eventsOfInterest:callback:userInfo:)`](/documentation/CoreGraphics/CGEvent/tapCreateForPid(pid:place:options:eventsOfInterest:callback:userInfo:))

[`tapEnable(tap:enable:)`](/documentation/CoreGraphics/CGEvent/tapEnable(tap:enable:))

Enables or disables an event tap.

[`tapIsEnabled(tap:)`](/documentation/CoreGraphics/CGEvent/tapIsEnabled(tap:))

Returns a Boolean value indicating whether an event tap is enabled.



---

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)