Determining the Keyboard Focus
Sometimes, it is hard to decide what to indicate as the focus location. Extended and discontiguous selection often confuse the issue, but the keyboard focus location should be considered independent of selection, even if an application normally links the two.
The following examples may clarify the distinction and help you learn to identify and indicate the keyboard focus location in your own application:
- Insertion bars in text. When the user moves an insertion point within text, it is usually drawn with the real system caret. If the application chooses to draw its own insertion point, it should still move the system caret invisibly, tracking the location of the visible insertion bar.
- Extended text selection. When the user makes an extended selection, one end of the selection is always the "active" or moving end, and that is the actual location of the keyboard focus. For example, to select three characters, you start with the insertion bar in an edit control, and then hold down the SHIFT key while pressing the right arrow twice. The end where you started is the "anchor," the stationary end; at the right, you should see the flashing caret marking the active end. If you hold down the SHIFT key and press another arrow key, it is the active end that moves, and that is where the system caret should be placed. You should display a visible insertion bar at the active end, because that is useful feedback for all users.
- On graphic objects. When a user moves the keyboard focus to a graphic object, such as an icon or a bitmap, an application should place the system caret invisibly over the same object so that the caret's rectangle covers the entire image. If there is an adjacent label, the caret should cover that as well.
- Within graphic objects. Sometimes, an application uses a single bitmap to represent several objects, such as a group of graphical buttons. The application usually indicates the focus by highlighting a portion of the bitmap, drawing a dotted rectangle over it, or even moving the mouse pointer. In addition to indicating the focus, the application should also place the system caret invisibly over the region of the bitmap that corresponds with the "hot spot" or object being referenced.
- Simple controls. If an application is drawing simple custom controls, such as a custom push button, the keyboard focus is associated with the entire control, so the entire control should be covered by the system caret. (This is necessary only for windowless custom controls. If the control is a window, the window takes the keyboard focus, so it is not necessary to identify it using the system caret.)
- Complex controls. A complex or composite control, such as a list box, can place the focus on individual elements within the larger control. In this case, an application should use the system caret to indicate the area of the particular item that has the focus. Even though the application might think of the collection of items as a single control, they should be treated as separate control elements when they are identified to external components.
- Spreadsheets. When the user navigates within a spreadsheet, the focus is usually placed on an entire cell, rather than on content within the cell. Often, this is indicated by a bold cell border, and the application should place the system caret over the entire cell. If the user begins editing the contents of a cell, the application should indicate the focus appropriately for the content text or graphics.
- Discontiguous selection. Discontiguous selection is usually supported among discrete items, rather than in text. There is always one item that has the keyboard focus or was most recently clicked by the mouse, and that object should be covered by the system caret. To see an example, select an item in a folder or in File Manager, and then hold down the CTRL key while pressing arrow keys to move the focus rectangle to a file that is not part of the selection.
- Mouse-only objects. Although applications should provide keyboard access to all their functionality, some objects can only be manipulated or selected using the mouse. In this case, you should treat the object when it is selected as if it received the keyboard focus and use the system caret appropriately to indicate that it has the focus. Of course, if the real keyboard focus moves, you should follow it, because the mouse-only object is no longer the object of the user's attention.