#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.

Advertisement

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

12 Responses to #301 – Using Access Keys

  1. Pingback: #302 – Access Keys for Controls that Don’t Have a Caption « 2,000 Things You Should Know About WPF

  2. Pingback: #303 – Define an Access Key for a Control Using an Underline « 2,000 Things You Should Know About WPF

  3. Pingback: #305 – Guidelines for Defining Access Keys « 2,000 Things You Should Know About WPF

  4. Pingback: #304 – Defining an Access Key That Gives Focus to a Different Control « 2,000 Things You Should Know About WPF

  5. Sevalle says:

    Why is it that with this implementation, pressing ALT is not actually a requirement anymore?
    How can I force it to be ALT+access key always?

  6. Steve Whisenhant says:

    Sean, we’re having some discussion on the minimum keyboard actions needed to set input focus by access key after pressing only the ALT key.Taken literally, this post indicates that both ALT and H must be pressed simultaneously after pressing ALT alone. Personal experience lead some to expect that the user may press only the H key after pressing only the ALT key. Perhaps this expectation grew from experience on Winforms or other pre-WPF platforms. Any experience or comments on this detail? Thanks.

    • Sean says:

      Steve, if you set up an ALT key for a control, e.g. by using an underline in its label, you do still need to hold the ALT key down while pressing the key in question. This is classic ALT key behavior–the access key is meant to be pressed while holding down the ALT key. WPF will wait to show you the underlined text corresponding to access keys until you press ALT. If you just press and release ALT, the access keys will be shown. But you cannot then just press the corresponding access key–you do need to press and hold the ALT key.

      Some applications do support this behavior–press ALT key then access key, rather than access key while pressing ALT key. E.g. Notepad, Visual Studio, Word, etc. But this behavior isn’t automatic in WPF, as far as I know. I think you’d have to do some extra work, beyond just defining the access key, to get this sort of behavior. Good future topic.

      Thanks!
      Sean

  7. Pingback: #838 – Using a Label’s Access Key to Give Focus to Another Control | 2,000 Things You Should Know About WPF

  8. Pingback: #839 – A Label’s Target Could Have Its Own Label | 2,000 Things You Should Know About WPF

  9. Pingback: #840 – Access Keys Should Be Unique within A Window | 2,000 Things You Should Know About WPF

  10. Pingback: #841 – Display Underlines for Access Keys at All Times | 2,000 Things You Should Know About WPF

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: