---
title: "init(input:modifierFlags:action:)"
framework: uikit
role: symbol
role_heading: Initializer
path: "uikit/uikeycommand/init(input:modifierflags:action:)"
---

# init(input:modifierFlags:action:)

Creates a key command that matches the specified input.

## Declaration

```swift
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 doc://com.apple.uikit/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 doc://com.apple.uikit/documentation/UIKit/UIKeyModifierFlags.
- `action`: The action method to execute on the responder object.

## Return Value

Return Value A newly initialized key command object.

## Discussion

Discussion After creating a key command object, you can: Add it as a child of a UIMenu using the menu’s init(title:image:identifier:options:children:) method. Add it to a view controller using the addKeyCommand(_:) method of the view controller. Override any responder class and return the key command directly from the responder’s keyCommands property.

## See Also

### Creating a key command object

- [init(title:image:action:input:modifierFlags:propertyList:alternates:discoverabilityTitle:attributes:state:)](uikit/uikeycommand/init(title:image:action:input:modifierflags:propertylist:alternates:discoverabilitytitle:attributes:state:).md)
- [init(coder:)](uikit/uikeycommand/init(coder:).md)
- [init()](uikit/uikeycommand/init().md)
- [Adding menus and shortcuts to the menu bar and user interface](uikit/adding-menus-and-shortcuts-to-the-menu-bar-and-user-interface.md)
- [Navigating an app’s user interface using a keyboard](uikit/navigating-an-app-s-user-interface-using-a-keyboard.md)
