#301 – Using Access Keys
May 17, 2011 12 Comments
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.
Pingback: #302 – Access Keys for Controls that Don’t Have a Caption « 2,000 Things You Should Know About WPF
Pingback: #303 – Define an Access Key for a Control Using an Underline « 2,000 Things You Should Know About WPF
Pingback: #305 – Guidelines for Defining Access Keys « 2,000 Things You Should Know About WPF
Pingback: #304 – Defining an Access Key That Gives Focus to a Different Control « 2,000 Things You Should Know About WPF
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?
I’m not sure I understand your question–you do still need to press ALT and then the access key.
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.
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
Pingback: #838 – Using a Label’s Access Key to Give Focus to Another Control | 2,000 Things You Should Know About WPF
Pingback: #839 – A Label’s Target Could Have Its Own Label | 2,000 Things You Should Know About WPF
Pingback: #840 – Access Keys Should Be Unique within A Window | 2,000 Things You Should Know About WPF
Pingback: #841 – Display Underlines for Access Keys at All Times | 2,000 Things You Should Know About WPF