Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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
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]);
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