Skip to content

Instantly share code, notes, and snippets.

@djromero
Created November 5, 2013 21:15
Show Gist options
  • Save djromero/7326451 to your computer and use it in GitHub Desktop.
Save djromero/7326451 to your computer and use it in GitHub Desktop.
DJRKeyboardEvents
/* .h */
@interface DJRKeyboardEvents : NSObject
+ (void)sendCommandC;
@end
/* .m */
#import "DJRKeyboardTools.h"
#import "DJRKeyboardEvents.h"
@implementation DJRKeyboardEvents
+ (void)sendCommandC
{
CGKeyCode _C = [[DJRKeyboardTools sharedInstance] keyCodeForChar:'c'];
CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState);
CGEventRef pasteCommandDown = CGEventCreateKeyboardEvent(source, _C, YES);
CGEventSetFlags(pasteCommandDown, kCGEventFlagMaskCommand);
CGEventRef pasteCommandUp = CGEventCreateKeyboardEvent(source, _C, NO);
CGEventPost(kCGAnnotatedSessionEventTap, pasteCommandDown);
CGEventPost(kCGAnnotatedSessionEventTap, pasteCommandUp);
CFRelease(pasteCommandUp);
CFRelease(pasteCommandDown);
CFRelease(source);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment