About Command Key Handling
Each view in your application has a set of key commands associated with it. This section describes how key commands are defined and associated with each view.To define a key command for one of your views, you need to define a
keyCommand
frame, as described in "The Command-Key Mapping Frame".You specify the method associated with a command key in the
keyMessage
slot of thekeyCommand
frame. The method need not be implemented in the same view as the command key.How Command Keys Are Found
The system software searches for command keys when the user presses one of the following keys:
However, it is also possible to force the system to search for key commands with every keystroke, regardless of whether the command key is down. To do this, set the text flag
- a function key
- the escape key
- any key pressed while the command key is held down
vAlwaysTryKeyCommands
in the key-view.The following list describes how the system searches for a
keyCommand
frame when the user enters a potential command key:
The search for a command key is analagous to the parent inheritance chain. You can link a slip to your base view, rather than its parent, which is normally the root view. This allows a key command defined in your base view to be available in the slip.
- The command search starts at the view that owns the caret.
- The system looks through the key commands registered in the current view for a
keyCommand
that matches the pressed key.- If the system finds a match, the search is complete.
- Otherwise, the system looks for a slot named
_nextKeyView
in the current view. This slot contains a reference to another view. If the_nextKeyView
slot is present, its contents are used as the next view in which to search.- If the
_nextKeyView
slot is not found, the system moves up to the current view's parent and uses that as the next view to search. This continues until the command is found or the root view has been searched.Key commands can be global (available regardless of the context), specific to a certain application, or specific to a slip within an application. Some commands may even be specific to a certain input field of a certain slip. In any case, each key command is associated with a certain view. Table 4-1 shows how commands are associated with views.
Table 4-1 Command definition views
Command Type Associated view Global commands Root view Application commands Application's base view Slip commands Slip's base view Field commands Field's view About Displaying Command-Key Combinations in Menus
To display a command-key combination for an item in a popup menu, you must define akeyMessage
frame for the item.For example, you can define a popup menu without command-key equivalents by passing an array to the
PopupMenu
view method. The following array creates a menu with three items:
The second item in the above menu contains an icon and the third item contains an icon and a mark.[
"one",
{icon: i, item: "two"}, {icon: ii, mark: $-, item: "three"} ]
To create the above menu with command-key combinations, you specify
keyMessage
slots in the item frames. When the menu is displayed, the system software searches for a matching command key and then uses the name, character, and modifiers defined in the foundkeyCommand
frame. For example, the menu could be defined with the following array:
The names for the second and third items in the menu array above are found in the corresponding[ "one",
{keyMessage: _DoSomething}, {keyMessage: _AnotherThing} ]
keyCommand
frames.
If you want to display a name in the menu that is not the same as the name specified in the
- Note
- To find a
keyCommand
frame that matches a menu item, the system looks for akeyCommand
frame whosekeyMessage
slot has the same value as thekeyMessage
slot in the menu item frame.![]()
keyCommand
frame, you can use akeyMessage
slot and an item slot in the item frame. In this case, the item name is used instead of the name in the matchingkeyCommand
frame. For example:
In the above example, the name "Something" is displayed in the menu.{keyMessage: _DoSomething, item: "Something"},
- Note
- An item defined with a
keyMessage
slot can also haveicon
andmark
slots.![]()
Main | Top of Section | What's New | Apple Computer, Inc. | Find It | Feedback | Help