---
title: UIKeyCommand
framework: uikit
role: symbol
role_heading: Class
path: uikit/uikeycommand
---

# UIKeyCommand

An object that specifies a key press perform on a hardware keyboard and the resulting action.

## Declaration

```swift
@MainActor class UIKeyCommand
```

## Overview

Overview Hardware keyboards allow a user to hold down the Control, Option, Command, or other modifier key and press another key in combination to initiate commands such as Cut, Copy, or Paste. You can use instances of this class to define custom command sequences that your app recognizes and then provide an appropriate response. To use this class, you create instances and associate them with your app’s responder objects. Each responder has a keyCommands property that you can redefine and use to return the key command objects that responder supports. Key command sequences are generated only for devices with an attached hardware keyboard. The system always has the first opportunity to handle key commands. Key commands that map to known system events (such as Cut, Copy, and Paste) are automatically routed to the appropriate responder methods. For other key commands, the system looks for an object in the responder chain with a key command object that matches the pressed keys. If it finds such an object, it then searches the responder chain, looking for the first object that implements the corresponding action method, and calls the first one it finds. iPad apps that run in macOS can use UIKeyCommand to create menu elements that have keyboard shortcuts.

## Topics

### 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(input:modifierFlags:action:)](uikit/uikeycommand/init(input:modifierflags:action:).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)

### Getting information about the key command

- [title](uikit/uikeycommand/title.md)
- [image](uikit/uikeycommand/image.md)
- [input](uikit/uikeycommand/input.md)
- [action](uikit/uikeycommand/action.md)
- [modifierFlags](uikit/uikeycommand/modifierflags.md)
- [UIKeyModifierFlags](uikit/uikeymodifierflags.md)
- [discoverabilityTitle](uikit/uikeycommand/discoverabilitytitle.md)
- [attributes](uikit/uikeycommand/attributes.md)
- [state](uikit/uikeycommand/state.md)

### Getting command alternatives

- [alternates](uikit/uikeycommand/alternates.md)
- [UICommandAlternate](uikit/uicommandalternate.md)

### Localizing keyboard shortcuts

- [allowsAutomaticLocalization](uikit/uikeycommand/allowsautomaticlocalization.md)
- [allowsAutomaticMirroring](uikit/uikeycommand/allowsautomaticmirroring.md)

### Overriding the key event delivery behavior

- [wantsPriorityOverSystemBehavior](uikit/uikeycommand/wantspriorityoversystembehavior.md)

### Associating data

- [propertyList](uikit/uikeycommand/propertylist.md)
- [UICommandTagShare](uikit/uicommandtagshare.md)

### Converting strings to key commands

- [Input strings for special keys](uikit/input-strings-for-special-keys.md)

### Deprecated

- [init(input:modifierFlags:action:discoverabilityTitle:)](uikit/uikeycommand/init(input:modifierflags:action:discoverabilitytitle:).md)

### Initializers

- [init(title:subtitle:image:selectedImage:preferredImageVisibility:action:input:modifierFlags:propertyList:alternates:discoverabilityTitle:attributes:state:)](uikit/uikeycommand/init(title:subtitle:image:selectedimage:preferredimagevisibility:action:input:modifierflags:propertylist:alternates:discoverabilitytitle:attributes:state:).md)

## Relationships

### Inherits From

- [UICommand](uikit/uicommand.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSCopying](foundation/nscopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)
- [UIAccessibilityIdentification](uikit/uiaccessibilityidentification.md)
- [UIMenuLeaf](uikit/uimenuleaf.md)

## See Also

### Menu elements and keyboard shortcuts

- [Adding menus and shortcuts to the menu bar and user interface](uikit/adding-menus-and-shortcuts-to-the-menu-bar-and-user-interface.md)
- [Adopting menus and UIActions in your user interface](uikit/adopting-menus-and-uiactions-in-your-user-interface.md)
- [UIMenuElement](uikit/uimenuelement.md)
- [UIAction](uikit/uiaction.md)
- [UICommand](uikit/uicommand.md)
- [UIDeferredMenuElement](uikit/uideferredmenuelement.md)
- [UIDeferredMenuElement.Provider](uikit/uideferredmenuelement/provider.md)
- [UIMenuElement.Attributes](uikit/uimenuelement/attributes.md)
- [UIMenuElement.State](uikit/uimenuelement/state.md)
- [UIMenuLeaf](uikit/uimenuleaf.md)
