So while working on a REALbasic project today, I finally was able to figure out what it was with keyboard mnemonics that bothered me so much.
REALbasic does them partially wrong!
I never could quite figure out what the deal was and why my REALbasic apps just didn't quite feel right when I was using them. So I sat down this morning and made a little test app to see if I could pin it down. It turns out that we only have the mnemonics half-way implemented.
Keyboard mnemonics (also called access keys or accelerator keys) are the characters that you see underlined in Windows applications. You'll see them on things like buttons, labels or menus and they're used for keyboard acceleration. The thought is that you'll provide an accelerator for the fields in your application so that the user can press a key (or key combo) and go straight to that field (and either do its action, like in the case of a button or a menu, or go to the sibling field in the case of a label). Basically, it's a way to quickly access and activate a UI element -- and they're very handy once you're used to using them.
Typical Windows applications will fire an accelerator key in one of two ways. If you hit Alt+ the mnemonic, then it will always fire its action, no matter where you are in the UI. So if you're in an EditField and you hit Alt+F, you'll (most likely) be taken to the File menu. The other way works depending on the focus control. Let's say you're in the file menu and you want to go to Exit (with the x underlined). You just have to hit X instead of Alt+X to fire the Exit menu. The reason you don't need to hit Alt at the same time is because the menu already has the focus.
Here's the example where I found the bug in REALbasic. Let's say you have a button on the window that has the focus control. In a typical Windows application, hitting just the mnemonic while the button has focus will cause the mnemonic to fire. There's no need to hit Alt+ the key (though you can, it will still work). REALbasic doesn't allow you to do this action though -- just hitting the key does not work. For an example of how this should work, hit Ctrl+Alt+Del (if you're in Windows 2000 or XP) and you'll be taken to a screen where the Lock Computer button has focus. Just hitting "T" will bring up the Task Manager.
So here are some things you should know about mnemonics:
- You create a mnemonic by putting an & in front of the character to be underlined. For exampe: &Testing will look like Testing.
- Mnemonics will always fire when you hit Alt+ the access key.
- If the focus control is one that does not accept keyboard input (basically, any focus control that's not an EditField, ComboBox or Listbox), then pressing just the access key causes the action to occur.
- Mnemonics are not always displayed. On some newer systems (like Windows 2000 and up), there is a system preference (on by default) to only show mmenonics after the Alt key is pressed. Personally, I think this is a UI nightmare. But it doesn't affect the way the mnemonics are fired. For example, if the focus is on the Lock Computer button, you can still hit just T to bring up the Task Manager, even though you can't see the underline.
- Mnemonics are the main reason you should never use Alt+ a key to fire a menu shortcut. Imagine having a button called Query (with the Q as the access key) and a menu item named Quit (with Alt+Q as the menu shortcut) -- what should happen when the user hits Alt+Q? I think the programmer should get fired. ;-)
- Keyboard mnemonics are case insensitive. "X" and "x" will both fire when the user hits the X key. However, it will also fire if the user hits Shift+X.
- Always make sure that you don't double up the mnemonics for any given view. By "view" I mean, any particular state in which the user has multiple choices for accelerator actions. So if you have a menubar, none of the top level menus should share a mnemonic with each other, or any of the items in the window. Furthermore, it's unacceptable for the top level menu currently selected to share a mnemonic with any of its submenus. However, when the menu is displayed, the subitems can share a mnemonic with the other top level menus (just not its owner menu). So File->Foobar is unacceptable, but File->Edict is fine even if there is an Edit top-level menu.
- If you have a StaticText with a mnemonic, you should usually only use the AcceleratorKey event (in REALbasic) to shift focus to the next control in the tab order. So if you are using a StaticText as a label for an EditField, hitting the StaticText's mnemonic should put the focus in the EditField.
- There are standard mnemonics that you should use when designing you UI. You can find them here (at the bottom of the page).
For more information about keyboard mnemonics, you should check out the Windows User Experience entry on the topic. But be warned -- the information is partially out of date and doesn't explain all the OS behaviors. For example, it doesn't mention the situations where you don't have to hit the Alt key to trigger the accelerator.
Couldn't find a contact form, so I'll just post this here. Feel free to delete this post.
It's Mnemonic. You swapped the first n and the second m.
Might help your search results a little... OTOH, there's probably more people who stumble over this greek word.
Cheers,
-- Uli
Thanks for the note Uli -- it's what I get for not spell checking my post. :-P
There, I edited the post and (I think) fixed all the spelling mistakes.
I forgot to add one to my list of things to note. Never put a mnemonic on OK or Cancel buttons if they have their Default or Cancel properties set (since you can already activate their action with Enter or Cancel).