Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Setting a Button’s Key Equivalent

A button can have a key equivalent, so that when the user presses that key, the button responds as though it’s been clicked.

Note that if you set the key equivalent to Return, that button becomes the default button.

You typically set a button’s key equivalent in Interface Builder. To do so, select the button and open the attributes pane of the inspector. Disclose the attributes for the button, click in the Key Equiv. field, and type the key or key combination you want to associate with the button. (You remove the key equivalent by pressing Clear.)

To set the key equivalent programmatically, use setKeyEquivalent: with the character. For example, to set it to Return, use:

[myButton setKeyEquivalent:@"\r"];

To set the button’s key equivalent to non-print character, you can use the key constants defined by NSResponder, as in the following example, which sets a button’s key equivalent to the left arrow key.

unichar arrowKey = NSLeftArrowFunctionKey;
[button setKeyEquivalent:[NSString stringWithCharacters:&arrowKey length:1]];


< Previous PageNext Page > Hide TOC


Last updated: 2007-12-11




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice