<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: -",
    "visionOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIKeyCommand/init(title:image:action:input:modifierFlags:propertyList:alternates:discoverabilityTitle:attributes:state:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "s:So12UIKeyCommandC5UIKitE5title5image6action5input13modifierFlags12propertyList10alternates20discoverabilityTitle10attributes5stateABSS_So7UIImageCSg10ObjectiveC8SelectorVSSSo0a8ModifierI0VypSgSaySo18UICommandAlternateCGSSSgSo23UIMenuElementAttributesVSo0wX5StateVtcfc"
  },
  "title" : "init(title:image:action:input:modifierFlags:propertyList:alternates:discoverabilityTitle:attributes:state:)"
}
-->

# init(title:image:action:input:modifierFlags:propertyList:alternates:discoverabilityTitle:attributes:state:)

Creates a key command that you can use as a menu element with a shortcut key, or a shortcut key only for a view controller.

```
@MainActor @preconcurrency convenience init(title: String = "", image: UIImage? = nil, action: Selector, input: String, modifierFlags: UIKeyModifierFlags = [], propertyList: Any? = nil, alternates: [UICommandAlternate] = [], discoverabilityTitle: String? = nil, attributes: UIMenuElement.Attributes = [], state: UIMenuElement.State = .off)
```

## Parameters

`title`

The title to display for the key command.

`image`

The image to display next to the key command’s title. Only the [`context`](/documentation/UIKit/UIMenuSystem/context) menu system supports the display of an image, and only when the app runs in iOS.

`action`

The action method to execute on the responder object.

`input`

The keys that a person must press. The string must contain one or more characters corresponding to the keys the 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).

`propertyList`

An object that contains data to associate with the key command.

`alternates`

An array of alternatives for the key command.

`discoverabilityTitle`

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

`attributes`

The attributes indicating the style of the key command.

`state`

The initial state of the key command.

## Discussion

After creating a key command object, you can:

- Add it as a child of a [`UIMenu`](/documentation/UIKit/UIMenu) using the menu’s [`init(title:image:identifier:options:children:)`](/documentation/UIKit/UIMenu/init(title:image:identifier:options:children:)) method.
- Add it to a view controller using the [`addKeyCommand(_:)`](/documentation/UIKit/UIViewController/addKeyCommand(_:)) method of the view controller.
- 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)