Class

UIKeyCommand

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

Declaration

@interface UIKeyCommand : UICommand

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, UIKit 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.

Topics

Creating a Key Command Object

+ commandWithTitle:action:input:modifierFlags:propertyList:

Creates a new key command object for the specified input.

Beta
+ commandWithTitle:action:input:modifierFlags:propertyList:alternates:

Creates a new key command object with alternative commands for the specified input.

Beta
+ keyCommandWithInput:modifierFlags:action:

Creates and returns a new key command object that matches the specified input.

+ keyCommandWithInput:modifierFlags:action:discoverabilityTitle:

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

Deprecated

Getting the Key Command Attributes

action

The command's action-method selector.

Beta
input

The string of characters corresponding to the keys that must be pressed to match this key command.

modifierFlags

The bit mask of modifier flags that must be pressed to match this key command.

setDiscoverabilityTitle:

An elaborated title that explains the purpose of the command.

Deprecated

Constants

UIKeyModifierFlags

These constants indicate which modifier keys are pressed.

Input Strings for Special Keys

These constants represent the text input strings that correspond to special nonvisible keys.

Relationships

Inherits From

See Also

Menu Items and Keyboard Shortcuts

UICommand

An object representing an action command.

Beta
UIMutableCommand

A mutable object that allows you to change nonessential properties of the command.

Beta
UIMutableKeyCommand

A mutable object that allows you to change nonessential properties of the key command.

Beta

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software