19

I'd like to make a UIKeyCommand that uses only the [return] key. So far I've tried:

UIKeyCommand *selectCommand = [UIKeyCommand keyCommandWithInput:@"\n" modifierFlags:0 action:@selector(chooseSelection:)];

There's no global constant for the enter key, like there is for up, down, left, right, and escape (from UIResponder.h):

// These are pre-defined constants for use with the input property of UIKeyCommand objects.
UIKIT_EXTERN NSString *const UIKeyInputUpArrow         NS_AVAILABLE_IOS(7_0);
UIKIT_EXTERN NSString *const UIKeyInputDownArrow       NS_AVAILABLE_IOS(7_0);
UIKIT_EXTERN NSString *const UIKeyInputLeftArrow       NS_AVAILABLE_IOS(7_0);
UIKIT_EXTERN NSString *const UIKeyInputRightArrow      NS_AVAILABLE_IOS(7_0);
UIKIT_EXTERN NSString *const UIKeyInputEscape          NS_AVAILABLE_IOS(7_0);

Is there anything else I could try to capture the return/enter key?

Jordan H
  • 52,571
  • 37
  • 201
  • 351
paulrehkugler
  • 3,241
  • 24
  • 45

1 Answers1

45

Using @"\r" for carriage return instead of @"\n" for newline should work.

paulrehkugler
  • 3,241
  • 24
  • 45
kvance
  • 1,479
  • 18
  • 22