<!--
{
  "availability" : [
    "macCatalyst: 13.1.0 -",
    "macOS: 10.4.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreGraphics",
  "identifier" : "/documentation/CoreGraphics/CGEvent/tapCreate(tap:place:options:eventsOfInterest:callback:userInfo:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Core Graphics",
      "CoreGraphics"
    ],
    "preciseIdentifier" : "c:@F@CGEventTapCreate"
  },
  "title" : "tapCreate(tap:place:options:eventsOfInterest:callback:userInfo:)"
}
-->

# tapCreate(tap:place:options:eventsOfInterest:callback:userInfo:)

Creates an event tap.

```
class func tapCreate(tap: CGEventTapLocation, place: CGEventTapPlacement, options: CGEventTapOptions, eventsOfInterest: CGEventMask, callback: CGEventTapCallBack, userInfo: UnsafeMutableRawPointer?) -> CFMachPort?
```

## Parameters

`tap`

The location of the new event tap. Pass one of the constants listed in [`CGEventTapLocation`](/documentation/CoreGraphics/CGEventTapLocation). Only processes running as the root user may locate an event tap at the point where HID events enter the window server; for other users, this function returns `NULL`.

`place`

The placement of the new event tap in the list of active event taps. Pass one of the constants listed in [`CGEventTapPlacement`](/documentation/CoreGraphics/CGEventTapPlacement).

`options`

A constant that specifies whether the new event tap is a passive listener or an active filter.

`eventsOfInterest`

A bit mask that specifies the set of events to be observed. For a list of possible events, see [`CGEventType`](/documentation/CoreGraphics/CGEventType). For information on how to specify the mask, see [`CGEventMask`](/documentation/CoreGraphics/CGEventMask). If the event tap is not permitted to monitor one or more of the events specified in the `eventsOfInterest` parameter, then the appropriate bits in the mask are cleared. If that action results in an empty mask, this function returns `NULL`.

`callback`

An event tap callback function that you provide. Your callback function is invoked from the run loop to which the event tap is added as a source. The thread safety of the callback is defined by the run loop’s environment. To learn more about event tap callbacks, see [`CGEventTapCallBack`](/documentation/CoreGraphics/CGEventTapCallBack).

`userInfo`

A pointer to user-defined data. This pointer is passed into the callback function specified in the `callback` parameter.

## Return Value

A Core Foundation mach port that represents the new event tap, or `NULL` if the event tap could not be created. When you are finished using the event tap, you should release the mach port using the function `CFRelease`. Releasing the mach port also releases the tap.

## Discussion

Event taps receive key up and key down events if one of the following conditions is true:

- The current process is running as the root user.
- Access for assistive devices is enabled. In OS X v10.4, you can enable this feature using System Preferences, Universal Access panel, Keyboard view.

After creating an event tap, you can add it to a run loop as follows:

1. Pass the event tap to the <doc://com.apple.documentation/documentation/CoreFoundation/CFMachPortCreateRunLoopSource(_:_:_:)> function to create a run loop event source.
2. Call the <doc://com.apple.documentation/documentation/CoreFoundation/CFRunLoopAddSource(_:_:_:)> function to add the source to the appropriate run loop.

---

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)