7

I've tried [myButton setKeyEquivalent:@"\n"] but that didn't work. I feel like there should be some predefined constant for it that I'm just missing.

Thanks.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Randall
  • 14,691
  • 7
  • 40
  • 60

3 Answers3

22

Try using "\r" instead of "\n" in this case.

I believe [myButton setKeyEquivalent:@"\r"] should do what you are looking for.

Matt Bierner
  • 58,117
  • 21
  • 175
  • 206
  • Do not set this in your - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil function... That's what happened to me. ;) – Git.Coach Aug 13 '14 at 04:23
1

Example for Swift 2.0:

let key = String(utf16CodeUnits: [unichar(NSEnterCharacter)], count: 1) as String
item.keyEquivalent = key
item.keyEquivalentModifierMask = Int(NSEventModifierFlags.CommandKeyMask.rawValue | NSEventModifierFlags.ControlKeyMask.rawValue)
seb
  • 2,350
  • 24
  • 30
0

Beware that "as is", this will require to type Command + Return (which I think is Enter). To have this work without Command I had to add [myButton setKeyEquivalentModifierMask:0];.

StuFF mc
  • 4,137
  • 2
  • 33
  • 32