KeyPress clarification

Hello Jules,

I need a little clarification regarding KeyPress when used in ApplicationCommandInfo::defaultKeypresses.

I see that if in a usual getCommandInfo() method I write:

result.defaultKeypresses.add(KeyPress('k', ModifierKeys::commandModifier, 0));

then pressing cmd-K normally executes the corresponding command. But if I write:

result.defaultKeypresses.add(KeyPress('?', ModifierKeys::commandModifier, 0));

when I press cmd-? (actually cmd-shift-?) I see the menubar correctly flashing, but the command is not executed.

If I change the code to:

result.defaultKeypresses.add(KeyPress('?', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0));

everything works, but I guess that if a hypothetical keyboard had the character '?' in a low position, the problem would arise again.

So, what is the proper way to handle this? At the moment I'm testing this on OSX 10.9.


The first parameter to the KeyPress constructor can't just be any unicode symbol because obviously you'll start hitting problems like this!

I'd recommend you don't hard-code any mappings other than letters and numbers because there are strange keyboard layouts out there where even the basic symbols will turn up all kinds of odd places. If you provide a KeyMappingEditorComponent then people can choose more keyboard-specific mappings unambiguously by pressing the key themselves.

Thanks, I understand. Perhaps I will go for something like 'cmd-E(xplain)'. Anyway I've done some tests and while the Finder or TextWrangler reliably responds to cmd-?, Firefox and Thunderbird do not.