iOS Developer Library

Developer

UIKit Framework Reference UIKeyCommand Class Reference

Options
Deployment Target:

On This Page
Language:

UIKeyCommand

The UIKeyCommand class specifies a key presses performed on a hardware keyboard and the resulting action that should take place. Hardware keyboards allow a user to hold down the Control, Option, Command, or other modifier key and press a 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. More...

Inheritance


Import Statement


import UIKit @import UIKit;

Availability


Available in iOS 7.0 and later.
  • Creates and returns a new key command object that matches the specified input.

    Declaration

    Swift

    init(input input: String, modifierFlags modifierFlags: UIKeyModifierFlags, action action: Selector) -> UIKeyCommand

    Objective-C

    + (UIKeyCommand *)keyCommandWithInput:(NSString *)input modifierFlags:(UIKeyModifierFlags)modifierFlags action:(SEL)action

    Parameters

    input

    The keys that must be pressed by the user. The string must contain one or more characters corresponding to the keys that were pressed. For a list of special characters that do not have a textual representation, see “Input Strings for Special Keys”.

    modifierFlags

    The bit mask of modifier keys that must be pressed. You can use this parameter to specify which modifier keys (Command, Option, and so on) must also be pressed by the user. You may specify more than one modifier key. For a list of possible values, see “UIKeyModifierFlags”.

    action

    The action method to execute on the responder object.

    Return Value

    The key command object.

    Discussion

    After creating a key command object, you associate it with a responder object by returning it from that object’s keyCommands property. You might have to reimplement that property to return your key command objects.

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • input input Property

    The string of characters corresponding to the keys that must be pressed to match this key command. (read-only)

    Declaration

    Swift

    var input: String { get }

    Objective-C

    @property(nonatomic, readonly) NSString *input

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • The bit mask of modifier flags that must be pressed to match this key command. (read-only)

    Declaration

    Swift

    var modifierFlags: UIKeyModifierFlags { get }

    Objective-C

    @property(nonatomic, readonly) UIKeyModifierFlags modifierFlags

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • These constants indicate which modifier keys are pressed.

    Declaration

    Swift

    struct UIKeyModifierFlags : RawOptionSetType { init(_ rawValue: Int) init(rawValue rawValue: Int) static var AlphaShift: UIKeyModifierFlags { get } static var Shift: UIKeyModifierFlags { get } static var Control: UIKeyModifierFlags { get } static var Alternate: UIKeyModifierFlags { get } static var Command: UIKeyModifierFlags { get } static var NumericPad: UIKeyModifierFlags { get } }

    Objective-C

    typedef { UIKeyModifierAlphaShift = 1 << 16, UIKeyModifierShift = 1 << 17, UIKeyModifierControl = 1 << 18, UIKeyModifierAlternate = 1 << 19, UIKeyModifierCommand = 1 << 20, UIKeyModifierNumericPad = 1 << 21, } UIKeyModifierFlags;

    Constants

    • AlphaShift

      UIKeyModifierAlphaShift

      The Caps Lock key is currently engaged.

      Available in iOS 7.0 and later.

    • Shift

      UIKeyModifierShift

      The Shift key is pressed.

      Available in iOS 7.0 and later.

    • Control

      UIKeyModifierControl

      The Control key is pressed.

      Available in iOS 7.0 and later.

    • Alternate

      UIKeyModifierAlternate

      The Option key is pressed.

      Available in iOS 7.0 and later.

    • Command

      UIKeyModifierCommand

      The Command key is pressed.

      Available in iOS 7.0 and later.

    • NumericPad

      UIKeyModifierNumericPad

      The key is located on the numeric keypad.

      Available in iOS 7.0 and later.

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • These constants represent the text input strings that correspond to special non visible keys.

    Declaration

    Swift

    let UIKeyInputUpArrow: NSString! let UIKeyInputDownArrow: NSString! let UIKeyInputLeftArrow: NSString! let UIKeyInputRightArrow: NSString! let UIKeyInputEscape: NSString!

    Objective-C

    NSString *const UIKeyInputUpArrow; NSString *const UIKeyInputDownArrow; NSString *const UIKeyInputLeftArrow; NSString *const UIKeyInputRightArrow; NSString *const UIKeyInputEscape;

    Constants

    • UIKeyInputUpArrow

      UIKeyInputUpArrow

      The string representing the up arrow key.

      Available in iOS 7.0 and later.

    • UIKeyInputDownArrow

      UIKeyInputDownArrow

      The string representing the down arrow key.

      Available in iOS 7.0 and later.

    • UIKeyInputLeftArrow

      UIKeyInputLeftArrow

      The string representing the left arrow key.

      Available in iOS 7.0 and later.

    • UIKeyInputRightArrow

      UIKeyInputRightArrow

      The string representing the right arrow key.

      Available in iOS 7.0 and later.

    • UIKeyInputEscape

      UIKeyInputEscape

      The string representing the Escape key.

      Available in iOS 7.0 and later.

    Import Statement