<!--
{
  "availability" : [
    "iOS: 18.4.0 -",
    "iPadOS: 18.4.0 -",
    "macCatalyst: 18.4.0 -",
    "visionOS: 2.4.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "WebKit",
  "identifier" : "/documentation/WebKit/WKWebExtensionContext/performCommand(for:)-25rd1",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "WebKit"
    ],
    "preciseIdentifier" : "c:objc(cs)WKWebExtensionContext(im)performCommandForKeyCommand:"
  },
  "title" : "performCommand(for:)"
}
-->

# performCommand(for:)

Performs the command associated with the given key command.

```
func performCommand(for keyCommand: UIKeyCommand) -> Bool
```

## Parameters

`keyCommand`

The key command received by the first responder.

## Return Value

Returns `YES` if a command corresponding to the UIKeyCommand was found and performed, `NO` otherwise.

## Discussion

This method checks for a command corresponding to the provided <doc://com.apple.documentation/documentation/UIKit/UIKeyCommand> and performs it, if available. The app should use this method to perform any extension commands at an appropriate time in the app’s responder object that handles the [`performCommand(for:)`](/documentation/WebKit/WKWebExtensionContext/performCommand(for:)-25rd1) action.

---

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)