Search code examples
objective-cxcodecocoansbuttonnscontrol

Give a Key equivalent to NSButton dynamically


I want to assign a key equivalent to an NSButton if the control is the first responder.


Solution

  • You can override becomeFirstResponder: and in your implementation call setKeyEquivalent:. If you want to remove the key equivalent when the button loses first responder status, override resignFirstResponder:.