<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIViewController/addKeyCommand(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIViewController(im)addKeyCommand:"
  },
  "title" : "addKeyCommand(_:)"
}
-->

# addKeyCommand(_:)

Associates the specified keyboard shortcut with the view controller.

```
func addKeyCommand(_ keyCommand: UIKeyCommand)
```

## Parameters

`keyCommand`

The key command to add.

## Discussion

This method lets you easily add key commands to the view controller without overriding the [`keyCommands`](/documentation/UIKit/UIResponder/keyCommands) property. The key commands you add to a view controller are applied to the active responder chain. When the user performs a key command, UIKit searches the responder chain (starting with the first responder) for an object capable of handling the specified action.

## See Also

[`keyCommands`](/documentation/UIKit/UIResponder/keyCommands)

The key commands that trigger actions on this responder.



---

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)