Class

CGEvent

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

Declaration

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 CFType.

Topics

Instance Properties

var flags: CGEventFlags

Returns the event flags of a Quartz event.

var location: CGPoint

Returns the location of a Quartz mouse event.

var timestamp: CGEventTimestamp

Returns the timestamp of a Quartz event.

var type: CGEventType

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

var unflippedLocation: CGPoint

Returns the location of a Quartz mouse event.

Type Properties

class var typeID: CFTypeID

Returns the type identifier for the opaque type CGEventRef.

Instance Methods

var data: CFData?

Returns a flattened data representation of a Quartz event.

func getDoubleValueField(CGEventField) -> Double

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

func getIntegerValueField(CGEventField) -> Int64

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

func keyboardSetUnicodeString(stringLength: Int, unicodeString: UnsafePointer<UniChar>?)

Sets the Unicode string associated with a Quartz keyboard event.

func post(tap: CGEventTapLocation)

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

func postToPSN(processSerialNumber: UnsafeMutableRawPointer?)

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

func setDoubleValueField(CGEventField, value: Double)

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

func setIntegerValueField(CGEventField, value: Int64)

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

func setSource(CGEventSource?)

Sets the event source of a Quartz event.

func tapPostEvent(CGEventTapProxy?)

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