Duplicating Hotkeys in a User Interface

A developer can experience a number of odd rules when working through an application design, especially when it comes to accessibility. The two main reasons to provide a hotkey within an application are to make the application more accessible for users who have a hard time using a mouse and to make it more efficient to use for keyboardists. Pressing Alt+Q to quit an application is often easier for these users than clicking the associated button with a mouse. Both actions accomplish the same goal, but using different approaches.

To create a hotkey in most languages, a developer simply adds an ampersand (&) in front of the hotkey character for a control’s caption (text) or its associated label (as in the case of a text box). For example, a caption of &Quit on a button will create a hotkey of Q and the user would press Alt+Q to perform the default action with that button without using the mouse or by tabbing between controls. Modern version of Windows show the hotkeys as underlined letters when the user presses Alt. (Older versions of Windows showed the hotkeys underlined at all times.)

A reader recently pointed out that there is a technical error in my book, “Start Here! Learn Microsoft Visual C# 2010 Programming.” The Array project that begins on page 90 shows two buttons that use the Q hotkey in Table 4-1 on page 92, LINQ and Quit. When it comes to buttons, every button must have a unique hotkey. That’s because using the hotkey doesn’t select the button—it performs a task. Pressing Alt+Q in the example as written will either perform the task provided by the LINQ button or quit the application (the action provided by the Quit button). To correct this problem, you need to specify the LINQ button use the N hotkey instead by changing the Text property from LIN&Q to LI&NQ. Pressing Alt+N will now execute the task performed by the LINQ button.

However, there is a little rule oddity that you need to know about hotkeys when designing applications. While you can’t duplicate the hotkey used for a button, you can duplicate the hotkey for fields. That’s because the hotkey selects the field. When the user presses the hotkey combination a second time, the next field that relies on the hotkey is selected. If there is a third field with the same hotkey, pressing the hotkey combination a third time will select that field. The fields are selected in order until they have all been selected, and then pressing the hotkey again will select the first field. Consequently, when you have an abundance of fields on a form and a lack of usable hotkeys, duplication becomes an option.

Remember that duplication only works with selections. For example, the label associated with a text box can contain a hotkey. Pressing the hotkey combination defined by the label will select the text box. The same can be said of checkboxes, listboxes, comboboxes, and any other field-type control you can image as long as the default action for that control is selection, rather than performing a task as a button would.

I don’t often make accessibility errors in my applications because it’s a big deal to me to make my applications as friendly and accessible as possible. However, it happens even with me, which points out the need to have other people test your code strenuously; looking for this very sort of problem. Normally, you don’t want to duplicate hotkeys, but when you must use duplicate hotkeys due to the number of controls on a form, use duplication only with controls that select a field. Let me know if you have any questions or comments at John@JohnMuellerBooks.com.


Author: John

John Mueller is a freelance author and technical editor. He has writing in his blood, having produced 99 books and over 600 articles to date. The topics range from networking to artificial intelligence and from database management to heads-down programming. Some of his current books include a Web security book, discussions of how to manage big data using data science, a Windows command -line reference, and a book that shows how to build your own custom PC. His technical editing skills have helped over more than 67 authors refine the content of their manuscripts. John has provided technical editing services to both Data Based Advisor and Coast Compute magazines. He has also contributed articles to magazines such as Software Quality Connection, DevSource, InformIT, SQL Server Professional, Visual C++ Developer, Hard Core Visual Basic, asp.netPRO, Software Test and Performance, and Visual Basic Developer. Be sure to read John’s blog at http://blog.johnmuellerbooks.com/. When John isn’t working at the computer, you can find him outside in the garden, cutting wood, or generally enjoying nature. John also likes making wine and knitting. When not occupied with anything else, he makes glycerin soap and candles, which comes in handy for gift baskets. You can reach John on the Internet at John@JohnMuellerBooks.com. John is also setting up a website at http://www.johnmuellerbooks.com/. Feel free to take a look and make suggestions on how he can improve it.