<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSButton/performKeyEquivalent(with:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSButton(im)performKeyEquivalent:"
  },
  "title" : "performKeyEquivalent(with:)"
}
-->

# performKeyEquivalent(with:)

Checks the button’s key equivalent against the specified event and, if they match, simulates the button being clicked.

```
func performKeyEquivalent(with key: NSEvent) -> Bool
```

## Parameters

`key`

The event containing the key equivalent.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if the key equivalent in `anEvent` matches the button’s key equivalent; <doc://com.apple.documentation/documentation/Swift/false> if it does not. This method also returns <doc://com.apple.documentation/documentation/Swift/false> if the button is blocked by a modal panel or the button is disabled.

## Discussion

If the character in `anEvent` matches the button’s key equivalent, and the modifier flags in `anEvent` match the key-equivalent modifier mask, [`performKeyEquivalent(with:)`](/documentation/AppKit/NSButton/performKeyEquivalent(with:)) simulates the user clicking the button and returning <doc://com.apple.documentation/documentation/Swift/true>. Otherwise, [`performKeyEquivalent(with:)`](/documentation/AppKit/NSButton/performKeyEquivalent(with:)) does nothing and returns <doc://com.apple.documentation/documentation/Swift/false>.

## See Also

[`keyEquivalent`](/documentation/AppKit/NSButton/keyEquivalent)

The key-equivalent character of the button.

[`keyEquivalentModifierMask`](/documentation/AppKit/NSButton/keyEquivalentModifierMask)

The mask specifying the modifier keys for the button’s key equivalent.



---

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)