How to set KeyEquivalent key for input / return in NSButton?

I tried [myButton setKeyEquivalent: @ "\ n"] but it did not work. I feel that for this there must be some kind of predefined constant that I just skipped.

Thank.

+3
source share
3 answers

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

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

+17
source

Beware that "as is", for this you will need to enter Command + Return (which, I think, is Enter). To do this work without a team, I had to add [myButton setKeyEquivalentModifierMask:0];.

0
source

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)
0
source

Source: https://habr.com/ru/post/1784425/


All Articles