Created
November 5, 2013 21:15
-
-
Save djromero/7326451 to your computer and use it in GitHub Desktop.
DJRKeyboardEvents
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
/* .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