<!--
{
  "availability" : [
    "iOS: 9.0.0 - 13.0.0",
    "iPadOS: 9.0.0 - 13.0.0",
    "macCatalyst: 13.1.0 - 13.1.0",
    "tvOS: 9.0.0 - 13.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIKeyCommand/init(input:modifierFlags:action:discoverabilityTitle:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIKeyCommand(cm)keyCommandWithInput:modifierFlags:action:discoverabilityTitle:"
  },
  "title" : "init(input:modifierFlags:action:discoverabilityTitle:)"
}
-->

# init(input:modifierFlags:action:discoverabilityTitle:)

Creates a key command object that matches the specified input and has a title.

```
convenience init(input: String, modifierFlags: UIKeyModifierFlags, action: Selector, discoverabilityTitle: String)
```

## Parameters

`input`

The keys that a person must press. The string must contain one or more characters corresponding to the keys a person pressed. For a list of special characters that don’t have a textual representation, see [Input strings for special keys](/documentation/UIKit/input-strings-for-special-keys).

`modifierFlags`

The bit mask of modifier keys that a person must press. You can use this parameter to specify which modifier keys (Command, Option, and so on) a person must also press. You may specify more than one modifier key. For a list of possible values, see [`UIKeyModifierFlags`](/documentation/UIKit/UIKeyModifierFlags).

`action`

The action method to execute on the responder object.

`discoverabilityTitle`

An elaborated title that explains the purpose of the key command.

## Return Value

The initialized key command object.

## Discussion

After creating a key command object, you can add it to a view controller using the [`addKeyCommand(_:)`](/documentation/UIKit/UIViewController/addKeyCommand(_:)) method of the view controller. You can also override any responder class and return the key command directly from the responder’s [`keyCommands`](/documentation/UIKit/UIResponder/keyCommands) property.

---

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)