macos:Keyboard
出自UXGuide.net
The Keyboard
目录 |
The keyboard’s primary use is to enter text. The keyboard may also be used for navigation, but it should always be an alternative to using the mouse. For more information about using the keyboard instead of the mouse, see “Keyboard Focus and Navigation”
The Functions of Specific Keys
There are four kinds of keys: character keys, modifier keys, arrow keys, and function keys. A character key sends a character to the computer. When the user holds down a modifier key, it alters the meaning of the character key being pressed or the meaning of a mouse action.
Character Keys
Character keys include letters, numbers, punctuation, the Space bar, and nonprinting characters—Tab, Enter, Return, Delete (or Backspace), Clear, and Esc (Escape). It is essential that your application use these keys consistently.
Space Bar
In text, pressing the Space bar enters a space between characters.
When full keyboard access is turned on, pressing the Space bar selects the item that currently has the keyboard navigation focus (the equivalent of clicking the mouse button).
Tab
In text-oriented applications, the Tab key moves the insertion point to the next tab stop. In other contexts, Tab is a signal to proceed; it means “move to the next item in a sequence.” The next item can be a table cell or a dialog text field. Shift-Tab navigates in the reverse direction. Pressing Tab can cause data to be entered before focus moves to the next item. For more details about navigating with the Tab key, see “Keyboard Focus and Navigation”
Enter
Most applications add information to a document as soon as the user enters it. In some cases, however, the application may need to wait until a whole collection of information is available before processing it. The Enter key tells the application that the user has finished entering information in a particular area of the document, such as a text field. While the user is entering text into a text document, pressing Enter has no effect.
If a dialog has a default button, pressing Enter (or Return) is the same as clicking it.
Return
In text, the Return key inserts a carriage return (a line break) and moves the insertion point to the beginning of the next line. In arrays, the Return key signals movement to the leftmost field one step lower (like a carriage return on a typewriter). As with Tab, pressing Return can cause data to be entered before focus moves to the next item.
If a dialog has a default button, pressing Return (or Enter) is the same as clicking it.
Delete (or Backspace)
Generally, if an item is selected, pressing Delete (or Backspace) removes the selection without putting it on the Clipboard. If nothing is selected, pressing Delete removes the character preceding the insertion point without putting it on the Clipboard. The Delete key has the same effect as the Delete command in the Edit menu.
The Option key can be used to extend a deletion to the next semantic unit (such as a word). The Command key can extend a deletion to the next semantic unit beyond that supported by Option. Recommended key combinations for text applications are Command-Delete to delete the previous word and Command–Fwd Del to delete the next word. Option-Delete could delete either the word containing the insertion point or the part of the word to the left of the insertion point, depending on what makes the most sense in your application; Option–Fwd Del could delete the part of the word to the right of the insertion point.
Clear
The Clear key has the same effect as the Delete command in the Edit menu: It removes the selection without putting it on the Clipboard. Not all keyboards have a Clear key, so don’t require its use in your application.
Esc (Escape)
The Esc (Escape) key basically means “let me out of here.” It has specific meanings in certain contexts. The user can press Esc in the following situations:
- In a dialog, instead of clicking Cancel
- To stop an operation in progress (such as printing), instead of pressing Command-period
- To cancel renaming a file or an item in a list
- To cancel a drag in progress
Pressing Esc should never cause the user to back out of an operation that would require extensive time or work to reenter. When the user presses Esc during a lengthy operation, display a confirmation dialog to be sure that the key wasn’t pressed accidentally.
Modifier Keys
Modifier keys alter the way other keystrokes or mouse clicks are interpreted. You should use these keys—Shift, Caps Lock, Option, Command, and Control—consistently as described here.
Shift
When pressed at the same time as a character key, the Shift key produces the uppercase alphabetic letter or the upper symbol on the key.
The Shift key is also used with the mouse for extending a selection or for constraining movements in graphics applications. For example, in some applications pressing Shift while using a rectangle tool draws squares.
Caps Lock
When activated, the Caps Lock key has the same effect on alphabetic keys as the Shift key, but it has no effect on nonalphabetic keys. When the Caps Lock key is down, the user must press Shift to type the upper character on a nonalphabetic key.
Option
When used with other keys, the Option key produces special symbols. The Keyboard Viewer, which users can add to the Input menu in the International pane of System Preferences, shows which keys generate each symbol.
The Option key can also be used with the mouse to modify the effect of a click or drag. For example, in some applications pressing Option while dragging an object makes a copy of the object.
Command
On most keyboards, the Command key is labeled with a cloverleaf symbol (
) and an Apple logo (
). Pressing the Command key at the same time as a character key tells the application to interpret the key as a command rather than a character. It can also be used with the mouse to modify the effect of a click or drag. Key combinations that use the Command key are described in “Keyboard Shortcuts”
Control
The Control key is used to modify the functions of other keys. Combined with a mouse click, it displays contextual menus (see “Contextual Menus”).
Control-F7 temporarily overrides a user’s preference for default navigation or full keyboard navigation in windows and dialogs. For more information, see “Keyboard Focus and Navigation”
- Cocoa: In Cocoa applications, the Control key has additional defined behaviors, as described in “Text System Defaults and Key Bindings” in Cocoa Event-Handling Guide in Cocoa Events & Other Input Documentation.
Arrow Keys
Apple keyboards have four arrow keys: Up Arrow, Down Arrow, Left Arrow, and Right Arrow. They can be used alone or in combination with other keys. Keyboard combinations using the arrow keys should be used only for shortcuts for mouse actions. It is never appropriate to implement only a keyboard combination and not provide a mouse-based way to perform the same action.
Appropriate Uses for the Arrow Keys
You can use arrow keys in these ways:
- In text, the arrow keys move the insertion point. When used with the Shift key, they extend or shrink the selection. If the user makes a selection and then presses the Right Arrow or Left Arrow key, the selection shrinks to zero length and the insertion point moves to the right or left edge of the selection.
- In lists, the arrow keys change the selection.
- In a graphics application, the arrow keys can be used to move a selected object the smallest possible increment (one pixel or one grid unit).
- In full keyboard access mode, the arrow keys move between values within a control.
Don’t use the arrow keys to:
- Move the mouse pointer onscreen
- Duplicate the function of the scroll bars
Moving the Insertion Point
When the insertion point moves vertically in a text document, its horizontal position is maintained in terms of screen pixels, not characters (in other words, the insertion point could move from the twenty-fifth character in a line down to the fiftieth character, depending on the font and size). As the insertion point moves from line to line, keep it as close as possible to its original horizontal position, moving it slightly left or right to the nearest character boundary.
The Option and Command keys are used as semantic modifiers with the arrow keys. As a general rule, the Option key increases the size of the semantic unit by 1 compared to the arrow keys alone, and the Command key enlarges the semantic unit again. The application determines what the semantic units are. In a word processor, typically the units are characters, words, lines, paragraphs, and documents. In a spreadsheet, a basic semantic unit could be a cell.
Table 8-1 describes the appropriate behavior of the arrow keys in text documents and fields. In some cases, the behavior describes what happens when the indicated keys are pressed more than once in succession.
Table 8-1 Moving the insertion point with the arrow keys
| Key | Moves insertion point |
|---|---|
| Right Arrow | One character to the right |
| Left Arrow | One character to the left |
| Up Arrow | To the line above, to the nearest character boundary at the same horizontal location |
| Down Arrow | To the line below, to the nearest character boundary at the same horizontal location |
| Option–Right Arrow | To the end of current word, then to the end of the next word |
| Option–Left Arrow | To the beginning of the current word, then to the beginning of the previous word |
| Option–Up Arrow | To the beginning of the current paragraph, then to the beginning of the previous paragraph |
| Option–Down Arrow | To the end of the current paragraph, then to the end of the next paragraph (insertion point is before a paragraph terminator, such as Return) |
| Command–Right Arrow | To the next semantic unit, typically the end of the current line, then the end of the next line |
| Command–Left Arrow | To the previous semantic unit, typically the beginning of the current line, then the previous unit |
| Command–Up Arrow | Upward in the next semantic unit, typically the beginning of the document |
| Command–Down Arrow | Downward in the next semantic unit, typically the end of the document |
Extending Text Selection With the Shift and Arrow Keys
Table 8-2 describes how to extend text selection by pressing the Shift key with the arrow keys.
Table 8-2 Extending text selection with the Shift and arrow keys
| Keys | Extends selection |
|---|---|
| Shift–Right Arrow | One character to the right |
| Shift–Left Arrow | One character to the left |
| Shift–Up Arrow | To the line above, to the nearest character boundary at the same horizontal location |
| Shift–Down Arrow | To the line below, to the nearest character boundary at the same horizontal location |
| Shift–Option–Right Arrow | To the end of the current word, then to the end of the next word |
| Shift–Option–Left Arrow | To the beginning of the current word, then to the beginning of the previous word |
| Shift–Option–Up Arrow | To the beginning of the current paragraph, then to the beginning of the next paragraph |
| Shift–Option–Down Arrow | To the end of the current paragraph, then to the end of the next paragraph (include the blank line between paragraphs in cut, copy, and paste operations) |
| Command–Shift–Right Arrow | To the next semantic unit, typically the end of the current line |
| Command–Shift–Left Arrow | To the previous semantic unit, typically the beginning of the current line |
| Command–Shift–Up Arrow | Upward in the next semantic unit, typically the beginning of the document |
| Command–Shift–Down Arrow | Downward in the next semantic unit, typically the end of the document |
If no text is selected, the extension begins at the insertion point. If text is selected by dragging, then the extension begins at the selection boundary. For example, in the phrase stop time, if the user places the insertion point between the “s” and “t” and then presses Shift–Option–Right Arrow, top is selected. However, if the user double-clicks so the whole word is selected, and then extends the selection left or up, it’s as if the insertion point were before the “s.” If the user extends the selection right or down, it’s as if the insertion point were between the “p” and the space after the word.
Reversing the direction of the selection deselects the appropriate unit. In the previous example, if the word stop is selected and the user presses Shift–Option–Right Arrow, so stop time is selected, and then presses Shift–Option–Left Arrow, time is deselected and stop remains selected.
Moving the Insertion Point in “Empty” Documents
Various text-editing programs treat empty documents in different ways. Some assume that an empty document contains no characters, in which case clicking at the bottom of a blank window causes the insertion point to appear at the top. In this situation, Down Arrow cannot move the insertion point into the blank space because there are no characters there.
Other applications treat an empty document as a page of space characters, in which case clicking at the bottom of a blank window puts the insertion point where the user has clicked and lets the user type characters there, overwriting the spaces. Whichever of these methods you choose for your application, it’s essential that you be consistent throughout.
Function Keys
There are 15 nondedicated function keys on desktop Macintosh keyboards (F1 through F15). Desktop Macintosh keyboards provide the following six dedicated function keys with standard behaviors. Because not all Macintosh computers have all function keys, don’t rely on these keys for critical keyboard shortcuts. For example, portable computers usually have 12 nondedicated function keys (F1 through F12), not 15 and don’t have Help keys or Forward Delete keys.
Help
Pressing the Help key may invoke the application’s help in Help Viewer. The key combination Command-Shift-/ (sometimes shortened to Command-?) should always display the application’s help in Help Viewer.
Forward Delete (Fwd Del)
Pressing the Forward Delete (labeled Del) key deletes the character after the insertion point, shifting everything following the removed character one position back. The effect is that the insertion point remains stationary while it “vacuums” the character or selection ahead of it.
If something is selected when Fwd Del is pressed, it has the same effect as pressing Delete (Backspace) or choosing Delete from the Edit menu.
You can support Option–Fwd Del to delete the next larger semantic unit, as described in “Moving the Insertion Point” but deleting more than one word at a time is inadvisable. Users prefer to select large amounts of text with the mouse so they have more control over what they’re deleting.
Home, End
Pressing the Home key is equivalent to moving the scrollers all the way to the top and to the left. In a text document, for example, pressing Home scrolls to the beginning of the document; in a spreadsheet, it may scroll to the beginning of the spreadsheet or to the beginning of a row. These keys should also work in scrolling lists to display the top or bottom of the list.
End is the opposite of Home: It scrolls to the end of a document.
If the beginning or end of the document is already reached, pressing Home or End produces a system alert sound. Pressing the Home or End key has no effect on the location of the insertion point or selected data.
Page Up, Page Down
Pressing Page Up or Page Down scrolls the document up or down one page. If an entire page can’t be displayed in the window, these keys first scroll incrementally up or down, until the top or bottom of the page is visible, before scrolling to the next page. These keys should also work in scrolling lists.
If the beginning or end of the document is reached, pressing Page Up or Page Down produces a system alert sound. Pressing the Page Up or Page Down key has no effect on the location of the insertion point or selected data.
Keyboard Shortcuts
Keyboard shortcuts are used throughout Mac OS X to provide quick ways for users to initiate certain actions. Many are provided by the operating system to meet both general usability needs and accessibility needs. The operating system therefore reserves certain keys and keyboard combinations for its use. These combinations, listed in Table 8-3 and Table 8-4 affect all applications and should not be used for any other function. Other keyboard shortcuts are used by the Universal Access features in Mac OS X and should be avoided.
In addition to the keyboard shortcuts reserved by the system, there are a large number of keyboard shortcuts that have a well established meaning, such as Command-S for Save and Command-Q for Quit. Users accustomed to running applications in Mac OS X expect these keyboard shortcuts to be available and to mean the same thing in each application they use. An application that overrides these shortcuts, such as one that uses Command-Q for a Query command instead of Quit, runs the risk of unnecessarily confusing and frustrating its users.
These common keyboard shortcuts are not reserved by the system, but they are highly recommended for applications that offer the associated commands. If your application does not offer all of these common commands, be sure you don't override these keyboard shortcuts and associate them with other commands your application does implement. A complete list of both system-reserved and commonly used keyboard shortcuts in Mac OS X is provided in “Keyboard Shortcuts Quick Reference”
You may also define keyboard shortcuts in your application for frequently used commands. Some guidelines on how to create appropriate shortcuts are in “Creating Your Own Keyboard Shortcuts” Other sections of this document list recommended keyboard shortcuts, where appropriate, to help you provide a consistent and familiar user experience in your application.
Reserved Keyboard Shortcuts
Don’t use the keys and key combinations in Table 8-3 for actions other than those listed in the table.
Table 8-3 Keyboard shortcuts reserved by the operating system
| Keys | Action |
|---|---|
| Esc | Cancel the current action |
| Command-Tab | Activate the most recently used open application |
| Command-Shift-Tab | Activate the least recently used open application |
| Command-Option-D | Show or hide the Dock |
| Command-H | Hide the active application |
| Command-Option-H | Hide other applications (all but the active one) |
| Command-Shift-Q | Log out |
| Command-Shift-Option-Q | Log out without confirmation |
| Command-Shift-Option-Control-Q | Force log out without confirmation |
| Command–Space bar | Show or hide Spotlight search field |
| Command-Option-Esc | Open the Force Quit dialog |
| Command-F5 | Turn VoiceOver on or off |
| Control-F1 | Turn full keyboard navigation on or off |
| Control-F7 | Toggle keyboard navigation in windows and dialogs |
| F9 | Tile or untile all open windows |
| F10 | Tile or untile all open windows in current application |
| F11 | Hide or show all open windows |
| F12 | Display or hide Dashboard |
Mac OS X also provides full keyboard access mode, in which users can navigate through windows and dialogs. When this mode is active, other keyboard combinations may be reserved by default. (See Accessibility Overview.)
Table 8-4 shows several key combinations that are reserved for use with localized versions of system software, localized keyboards, keyboard layouts, and input methods. These key combinations don’t correspond directly to menu commands.
Table 8-4 Key combinations reserved for international systems
| Keys | Action |
|---|---|
| Command–Space bar | Rotate through enabled script systems |
| Command–Option–Space bar | Rotate through keyboard layouts and input methods within a script |
| Command–modifier key–Space bar | Apple reserved |
| Command–Right Arrow | Change keyboard layout to current layout of Roman script |
| Command–Left Arrow | Change keyboard layout to current layout of system script |
Creating Your Own Keyboard Shortcuts
Apple may reserve other keyboard shortcuts in the future, so be careful about adding your own. Before you consider creating a keyboard shortcut, be sure to look at the keyboard shortcuts listed in “Keyboard Shortcuts Quick Reference” so you can avoid overriding the shortcuts users already know.
You might also consider examining the keyboard shortcuts used in other applications that target the same user audience your application targets. If your users are likely to be familiar with these other applications, you should try to avoid overriding the shortcuts they're used to using.
You should provide keyboard shortcuts only for frequently used commands, not for every command. Presenting the user with too many keyboard shortcuts can be overwhelming and can make an application's user interface seem difficult to learn.
Use the Command key as the main modifier key for keyboard equivalents. For a command that complements another more common command, you can add Shift. The table below shows some recommended keyboard equivalents using Shift and their relation with the command they complement.
Table 8-5 Recommended keyboard shortcuts using Shift to complement other commands
| Keys | Command | Complemented command |
|---|---|---|
| Command-Shift-A | Deselect All | Command-A (Select All) |
| Command-Shift-G | Find Previous | Command-G (Find Again) |
| Command-Shift-P | Page Setup | Command-P (Print) |
| Command-Shift-S | Save As | Command-S (Save) |
| Command-Shift-V | Paste as (Paste as Quotation, for example) | Command-V (Paste) |
| Command-Shift-Z | Redo | Command-Z (Undo) |
If there’s a third, less common command that’s related to a pair of commands that use Command and Command-Shift, you can use Command-Option for the third command’s keyboard equivalent. In the example in Table 8-6 Save All could be a dynamic menu item (see “Naming Menu Items”) that appears in place of Save when the user presses the Option key (rather than a separate menu item). Use combinations like these very rarely.
Table 8-6 Example of using Option to modify a shortcut already using Command
| Keys | Command |
|---|---|
| Command-S | Save |
| Command-Shift-S | Save As |
| Command-Option-S | Save All |
Also use Option for a keyboard shortcut that is a convenience or power-user feature. For example, the Finder uses Command-Option-W for Close All Windows and Command-Option-M for Minimize All Windows.
Because the Control key is already used by some of the universal access features as well as in Cocoa text fields where Emacs-style key bindings are often used, it should be used as a modifier key only when necessary.
Remember that other languages may require modifier keys to generate certain characters. For example, on a French keyboard, Option-5 generates the “{“ character. You can safely use the Command key as a modifier, but avoid using Command and an additional modifier with characters not available on all keyboards. If you must use a modifier key in addition to the Command key, try to use it only with the alphabetic characters (a through z).
When adding custom keyboard shortcuts, try to avoid shortcuts that add a modifier key (such as Option or Shift) to an existing shortcut if the shortcuts have an unrelated function. For example, don’t use Shift-Command-Z as a keyboard shortcut for a command that is unrelated to Undo. Using that shortcut for Redo is appropriate, but using it for something like Calculate or Check Mail is confusing. If you can’t find a unique and easy-to-use keyboard shortcut for a command, don’t use one at all; keep in mind that users may have difficulty pressing multiple modifier keys anyway.
User-Defined Keyboard Shortcuts
Users may modify your application’s keyboard shortcuts and some of the system in Keyboard & Mouse preferences. Even though users can remap keyboard shortcuts, you should adhere to the shortcuts recommended throughout this document. Doing so provides a more consistent user experience. See “Keyboard Shortcuts Quick Reference” for a list of all the reserved and recommended combinations.
In default keyboard access mode, focus moves only between fields that receive keyboard input. Mac OS X also provides the option of full keyboard access mode, in which users can navigate through windows and dialogs. This section discusses the default keyboard access mode. For information on the full keyboard access mode, see Accessibility Overview.
When using the mouse is undesirable, difficult, or impossible, users can use the keyboard to move the onscreen focus (highlight) to text entry fields, list boxes that support type-ahead, scrolling lists, column views, and list views. In Roman systems, focus always begins at the first field that accepts keyboard input and follows a reading path from upper left to bottom right.
Focus is indicated with a ring in the appearance color (Aqua or Graphite) as shown in Figure 8-1 and Figure 8-2
Figure 8-1 Keyboard focus for a text field
Figure 8-2 Keyboard focus for a scrolling list
In list and column views, selected items should be highlighted to the full column width or row height. In column view, the selected item has a dark highlight and the parent item has a lighter highlight. When a window becomes inactive, all selections inside it should become the lighter highlight color.
Figure 8-3 Primary highlight color on child item; secondary color on parent
Pressing the Tab key navigates between controls. Shift-Tab navigates in the reverse direction. The arrow keys provide navigation within controls. In list views, the Right Arrow and Left Arrow keys open and close disclosure triangles.
Type-Ahead and Key-Repeat
When the user types faster than the computer can handle or when the computer is unable to process the keystrokes, the keystrokes are queued for later processing. This queuing is called type-ahead. There is a limit (varying with the computer) to the number of keystrokes that can be queued, but it’s usually not reached unless the user types while the application is performing a lengthy operation.
When a character key is held down for a certain amount of time, it starts repeating automatically. The user can make adjustments to this feature, called key-repeat, in Keyboard & Mouse preferences.
An application can tell whether keystrokes are generated by key-repeat or by the same key being pressed numerous times. Your application can disregard key-repeat keystrokes; it should ignore them in keyboard shortcuts that begin with the Command key.
Key-repeat works only when the application is ready to accept keyboard input; it does not function during type-ahead.