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

# init(input:modifierFlags:action:)

Creates a key command that matches the specified input.

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

## 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.

## Return Value

A newly initialized key command object.

## 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)