Skip to content

Instantly share code, notes, and snippets.

@elpsk
Created September 3, 2014 22:40
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 elpsk/156bbd11d8fcd74fc190 to your computer and use it in GitHub Desktop.
Save elpsk/156bbd11d8fcd74fc190 to your computer and use it in GitHub Desktop.
MAC OSX - Keystroke listener
// listen for keystrokes
[NSEvent addGlobalMonitorForEventsMatchingMask:NSKeyDownMask handler:^(NSEvent *event)
{
NSLog(@"%lui -- %@", (unsigned long)[event modifierFlags], event.characters );
//
// if flag and char do something, like bring to front the application
// 256 is ESC, in my case.
//
if ( [event modifierFlags] == 256 && [[event charactersIgnoringModifiers] compare:@""] == 0 )
{
NSLog(@"-------- IN --------");
[NSApp activateIgnoringOtherApps:YES];
}
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment