Skip to content

Instantly share code, notes, and snippets.

@sarnesjo
Created May 1, 2011 01:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sarnesjo/950169 to your computer and use it in GitHub Desktop.
Save sarnesjo/950169 to your computer and use it in GitHub Desktop.
An attempt to map modifier key events to regular key up/key down events...
// FIXME: does not work as intended if both left and right modifier key are pressed simultaneously!!!
- (NSUInteger)modifierFlagMaskForKeyCode:(unsigned short)keyCode
{
switch(keyCode)
{
case 54: // right cmd
case 55: // left cmd
return NSCommandKeyMask;
case 56: // left shift
case 60: // right shift
return NSShiftKeyMask;
case 57: // caps lock
return NSAlphaShiftKeyMask;
case 58: // left alt
case 61: // right alt
return NSAlternateKeyMask;
case 59: // left ctrl
case 62: // right ctrl
return NSControlKeyMask;
}
return 0;
}
- (void)flagsChanged:(NSEvent *)event
{
if([event modifierFlags] & [self modifierFlagMaskForKeyCode:[event keyCode]])
NSLog(@"down: %u", (unsigned int)[event keyCode]);
else
NSLog(@"up: %u", (unsigned int)[event keyCode]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment