Skip navigation.
 
mlcatching modifier keys in a keydown event
FROM : Travis Siegel
DATE : Sat Jul 01 02:45:13 2006

Hello all.
I'm having trouble figuring out how to catch modifier keys (command/
option/shift/whatever)
My keydown event is like this:
- (BOOL) onKeyDown: (NSEvent *)theEvent
{
   NSString *keyString = [theEvent characters];
   unichar key = [keyString characterAtIndex:0];
   BOOL keyIsHandled = YES;
   OSStatus result = noErr;

   switch (key) {
       case NSUpArrowFunctionKey:
break;
       case NSDownArrowFunctionKey:
   break;
       case NSCarriageReturnCharacter:
       case NSEnterCharacter:
           break;
       case ' ':
           break;
       case 'A':
       break;
       case 'E':
break;

       default:
           keyIsHandled = NO;
           break;
   }
   NSAssert1 (!result, @"key handled was %d", result);
   return keyIsHandled;
}
   }
I have no trouble getting regular keypresses, and even the function 
keys that have values.
But what I can't figure out is how to pickup a key like command-L, or 
something more complex command-option-L.
I know these keys are returned, and there's four bytes in the key 
event string, but I have no idea how to interpret these codes.
Do I need another function to handle those keys, or is there some 
kind of ns values like there is for the arrow keys I can use?
If anyone has some help on this, I'd be forever greatful.

Related mailsAuthorDate
mlcatching modifier keys in a keydown event Travis Siegel Jul 1, 02:45
mlRe: catching modifier keys in a keydown event Shawn Erickson Jul 1, 03:21
mlRe: catching modifier keys in a keydown event Matt Neuburg Jul 1, 15:56