-
-
Save thomcc/6f41cd2043130319c8dc3af4e8701ee4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { | |
[NSEvent addLocalMonitorForEventsMatchingMask: (NSKeyDownMask | NSKeyUpMask | NSFlagsChangedMask) | |
handler: ^(NSEvent *event) { | |
NSEvent *result = event; | |
int flags = [event modifierFlags]; | |
int cmdDown = !!(flags & NSCommandKeyMask); | |
int shiftDown = !!(flags & NSShiftKeyMask); | |
int ctrlDown = !!(flags & NSControlKeyMask); | |
int altDown = !!(flags & NSAlternateKeyMask); | |
switch ([event type]) { | |
case NSKeyDown: { | |
unichar c = [[event charactersIgnoringModifiers] characterAtIndex:0]; | |
printf("KEYDOWN Key: %d, Cmd: %d, Shift: %d, Ctrl: %d, Alt: %d\n", c, cmdDown, shiftDown, ctrlDown, altDown); | |
result = nil; | |
} break; | |
case NSKeyUp: { | |
unichar c = [[event charactersIgnoringModifiers] characterAtIndex:0]; | |
printf("KEYUP Key: %d, Cmd: %d, Shift: %d, Ctrl: %d, Alt: %d\n", c, cmdDown, shiftDown, ctrlDown, altDown); | |
result = nil; | |
} break; | |
case NSFlagsChanged: { | |
printf("FLAGS Cmd: %d, Shift: %d, Ctrl: %d, Alt: %d\n", cmdDown, shiftDown, ctrlDown, altDown); | |
} break; | |
default: | |
break; | |
} | |
return result; | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment