Using Keyboard Interface Control in Windows

A window’s first responder is often a view object selected by the user clicking it. For text fields and other view objects (mainly subclasses of NSControl), the user can select the first responder with the keyboard using the Tab and Shift keys. The NSView class defines the methods for setting up and examining the loop of objects that the user can select in this manner. A view that’s the first responder is called the key view, and the views that can become the key view in a window are linked together in the window’s key view loop. You normally set up the key view loop using Interface Builder, establishing connections between the nextKeyView outlets of views in the window and setting the window’s initialFirstResponder outlet to the view that you want selected when the window is first placed onscreen. If you do not set this outlet, the window sets a key loop (not necessarily the same as the one you would have specified!) and picks a default initial first responder for you.

In addition to the key view loop, a window can have a default button cell, which uses the Return (or Enter) key as its key equivalent. The setDefaultButtonCell: method establishes this button cell; you can also set it in Interface Builder by setting a button cell’s key equivalent to '\r'. The default button cell draws itself as a focal element for keyboard interface control unless another button cell is focused on. In this case, it temporarily draws itself as normal and disables its key equivalent. Another default key established by the NSWindow class is the Escape key, which immediately aborts a modal loop (described in “How Modal Windows Work”).

See NSResponder Class Reference for more information on keyboard interface control.