- A Concurrent Affair - https://www.concurrentaffair.org -

Keyboard Mnemonics on the Mac

Ok, I have neglected the blog for a while, partly out of necessity as I was on vacation and without internet access, partly out of laziness. Neither of those reasons implies I didn’t do anything, though (yes, I work during my vacation because I enjoy my work), but I’ll fill in the gaps in a later post.

I was just going through some of the // TODO items I had left in the DrJava codebase, and I came across a problem with the “Import Package” checkbox in the “Auto Import Class” dialog in the Interactions Pane (the dialog is displayed if a class name is not recognized because it has not been imported yet).

For this checkbox, I have used Java’s setMnemonic('p'). On Windows, that means you press Alt+P, and the state of the checkbox toggles. On the Mac, however, it toggles AND inserts a Greek lower-case pi character. I searched for other uses of setMnemonic() in DrJava, and we have a bunch of them:

A good reference for the different Alt key combinations is at: Everything2 Special Alt key characters & accents [1].

As a summary, Java mnemonic on Mac OS are broken, and we need to do something about it. There are several options:

  1. We attempt to block the symbols from being inserted, but at least for Alt-E and Alt-N, possibly for other key combinations as well, the treatment might very well be a hard-wired Mac OS feature. Blocking these symbols would also make DrJava pretty much unusable for users who program in languages that use diacritics: German, French, and the Scandinavian languages, just to name a few.
  2. We ditch mnemonics on the Mac completely. Even though I miss the ability to open menus like a File menu using Alt-F as can be done Windows, I have never seen a Mac application that does that. So not using these mnemonics on Mac OS would probably make DrJava more compliant with Apple’s user interface guidelines.
    There’s one caveat: We have to make sure that every feature that was accessible using a mnemonic is still accessible in some way on the Mac, probably using the mouse. However, I think that already is the case.
  3. We use a different key for mnemonics on the Mac, e.g. Ctrl. This could work in most cases, since keyboard shortcuts like Ctrl-S to save a file on Windows are mapped to Command-S on the Mac. I checked, and the only places where we seem to have hard-coded the Ctrl, even on the Mac, is in the following places:
    • Find/Replace panel: Ctrl-Enter inserts a newline instead of invoking the “Find Next” action; Ctrl-Tab inserts a tab instead of switching focus to the next component
    • Interactions pane: Ctrl-Enter, same as above.
    • Ctrl-Backtick/Ctrl-Shift-Backtick to switch back and forth between recent documents.

    These cannot be replaced since Command-Tab toggles between MacOS applications and Command-Backtick between individual windows. Using Ctrl-Enter even though Command-Enter would work seems more consistent than using Ctrl-Tab to insert a tab, but Command-Enter to insert a newline.
    I don’t know how difficult to implement this option is because setMnemonic() asks either for a character like 'p' or for a VK_xxx constant, but what mask key to use can’t be specified.

Considering these three options (that I can think of — please chime in if you have a different idea), I believe we should choose option 2) and disable mnemonics on the Mac.

It would still be very interesting to figure out how we can use the Mac OS-standard Command-Backtick/Command-Shift-Backtick to switch between documents.

[2] [3]Share [4]