#841 – Display Underlines for Access Keys at All Times

Normally, the underline characters that are used to indicate access keys for controls are displayed only after you press the Alt key.

For example, before you press the Alt key, you won’t see any underlines:


But once you press the Alt key, you’ll see underlines indicating access keys for all controls:



You can, however, change a setting in the Control Panel so that the underlines are always visible.

In Control Panel, click on Ease of Access.  (Instructions below apply to Windows 8).



Click on Ease of Access Center.



Click on the Make the keyboard easier to use option.



Enable the option Underline keyboard shortcuts and access keys.



The underlines indicating access keys will now be displayed immediately when you start your application.



#305 – Guidelines for Defining Access Keys

Microsoft defines the following guidelines for defining access keys, in the Windows User Experience Interaction Guidelines.

  • Use wider characters for the access key  (e.g. avoid ‘i’, ‘I’)
  • Use a distinctive consonant or vowel  (e.g. _Sort rather than So_rt)
  • Avoid using characters that make it hard to see the underline  (e.g. characters with descenders, like ‘y’)
  • Assign an access key to every menu item
  • For dynamically created menu items (e.g. list of recent files), use numeric access keys
  • Assign unique keys within a particular menu
  • First choice is to use first character of first or second word in label
  • Assign an access key to every control in a window that takes input, or to a nearby label
  • Assign unique keys within a particular window or dialog
  • Don’t assign access keys for OK and Cancel buttons
  • Don’t assign an access key to a control that has no associated caption or label

#304 – Defining an Access Key That Gives Focus to a Different Control

For controls that don’t have their own textual caption, it’s common to define an access key for a nearby label.  When that access key is activated, the control without the caption gets the focus.

In the example below, there is a TextBox where you can enter your name and the nearby Label “Enter Name”.  This screenshot was taken after the ALT key was pressed, so the ‘N’ in “Enter Name” is underlined, indicating that ‘N’ is the access key.  If the user presses ALT-N, the TextBox will get focus and they can then begin typing the name.

You can specify the control that should be the target of an access key by using the Target property on the control where you define the access key.

            <!-- Access key on Label gives focus to TextBox -->
            <Label Content="Enter _Name:" VerticalAlignment="Center" Target="txtName" />
            <TextBox Name="txtName" Width="150" Margin="10"/>

#303 – Define an Access Key for a Control Using an Underline

You define an access key for a control by including an underscore ‘_’ character immediately before the desired access key character in the control’s caption or label.  You can then use that character, in combination with the ALT key, to activate the control or give it focus.

Here are some examples:

        <Button Content="_Eggs" Width="100" Margin="10" Click="Button_Click"/>
        <CheckBox Content="_I'm hungry now" Margin="10" HorizontalAlignment="Center"/>
        <RadioButton Content="Pick _Me" Margin="10" HorizontalAlignment="Center"/>

#302 – Access Keys for Controls that Don’t Have a Caption

Access keys are ALT key shortcuts that allow you to activate a control, or give focus to a control.

For controls that have captions, like buttons and checkboxes, the access key is the character in the caption that is underlined when you press the ALT key.

For controls that do not have a caption, a user interface will typically include a label near the control that does have an access key.  Activating the access key of that label will typically give focus to the nearby control.

In the example below, the TextBox and ComboBox controls do not have access keys of their own.  But both have an associated label with an access key.

Activating the access key of one of these labels will give focus to their associated control.

#301 – Using Access Keys

An access key is a keyboard shortcut assigned to a control that has an associated text label.  Access keys allow users to activate a control using the keyboard rather than using the mouse to click on the control.

Access keys are triggered by pressing the ALT key along with one of the characters in the control’s label.  When you click or hold the ALT key, Windows will show you the access keys for all controls in the current window by underlining the character used for the access key.

Here’s the main window for an application that was just started.  The access keys are not visible.

When you press the ALT key, Windows underlines the characters corresponding to the access keys.

You can activate a control by pressing the associated access key after pressing ALT.  Pressing ALT-H in this window would be equivalent to clicking on the “Ham” button.