tags:

views:

24

answers:

1

I need to know which NSString values i can use for key equivalents.

I can't find out what to use for

  • cursor keys
  • delete/backspace
  • function keys
  • numpad items
A: 

I wrote a program to look them up. Here's the output:

2010-08-14 06:12:24.676 KeyEquivalents[2313:a0b] Key equivalent for Return: 
 (<0d>)
2010-08-14 06:12:24.678 KeyEquivalents[2313:a0b] Key equivalent for Enter:  (<03>)
2010-08-14 06:12:24.679 KeyEquivalents[2313:a0b] Key equivalent for Backspace:  (<08>)
2010-08-14 06:12:24.680 KeyEquivalents[2313:a0b] Key equivalent for Forward delete:  (<7f>)

Return is carriage return, ctrl-M in the terminal world; Enter is ctrl-C in the terminal world; Backspace is the backspace character, ctrl-H in the terminal world; forward delete is the delete character.

Pretty much all the key equivalents are simply the character that you would normally enter for that. Return is a return character, backspace is a backspace character, tab is a horizontal tab character—no surprises.

The same goes for the keys on the numeric keypad, which aren't distinguished from their cousins in the main keyboard. We are dealing with characters here, after all, and both sets of keys enter the same characters. I don't think there is a way to set a menu's key code rather than its key-equivalent character; you would need to implement this yourself.

Note that “delete” (as the opposite of backspace) is called “forward delete” on the Mac, as backspace is usually called delete.

Peter Hosey
And what about function keys?I found a way to display them as key equivalent in menus but they are not invoked. The argument with the character might be right (well backspace/enter is not a character either) but it only gives Apple a bad name. Their Key handling is so terrible broken anyway.
Lothar
Backspace is a character (ASCII #8, exactly the character that gets bound to it when you set it in IB), and Apple's key handling is not “terrible broken”. If it were, it wouldn't work so well with other key layouts; in my experience as a Dvorak user, it's always custom key handling that screws that up. See WWDC 2010 session 145 to learn how Apple's key handling works; it's an elegant, flexible system. As for the function keys, those are defined in NSEvent.h. Incidentally, I noticed a key modifier mask there for keypad keys; you could set that on any menu items that should be keypad-specific.
Peter Hosey
I just tested, and it doesn't help—the menu item matches the character regardless of whether the menu item has `NSNumericPadKeyMask`. Sounds like a bug to me, so I suggest filing it: https://bugreport.apple.com/ In the meantime, you can use the information in #145 to handle that yourself.
Peter Hosey