public
Last active

An attempt to map modifier key events to regular key up/key down events...

  • Download Gist
gistfile1.m
Objective-C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
// 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]);
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.