#import <Foundation/Foundation.h>
#import "Cocoa/Cocoa.h"

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSApplication* app = [NSApplication sharedApplication];
        
        NSLog(@"Open Any Text Editor and place your cursor");
        [NSThread sleepForTimeInterval: 6];
        
        CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
        
        NSLog(@"Key events will start now");
        [NSThread sleepForTimeInterval: 2];
        
        //SHIFT KEY PRESS
        CGEventRef event1 = CGEventCreateKeyboardEvent(source,(CGKeyCode)56, YES);
        CGEventFlags flags = CGEventSourceFlagsState(kCGEventSourceStateHIDSystemState);
        NSLog(@"Shift up flag %llu \n", flags);
        CGEventPost(kCGHIDEventTap, event1);
        CFRelease(event1);
        
        [NSThread sleepForTimeInterval: 1];
        
        //'a' KEY PRESS
        CGEventRef event2 = CGEventCreateKeyboardEvent(source,(CGKeyCode)0, YES);
        flags = CGEventSourceFlagsState(kCGEventSourceStateHIDSystemState);
        NSLog(@"Shift down flag %llu \n", flags);
        CGEventPost(kCGHIDEventTap, event2);
        CFRelease(event2);

        [NSThread sleepForTimeInterval: 1];
        
        //'a' KEY RELEASE
        CGEventRef event3 = CGEventCreateKeyboardEvent(source,(CGKeyCode)0, NO);
        flags = CGEventSourceFlagsState(kCGEventSourceStateHIDSystemState);
        NSLog(@"Shift down flag %llu \n", flags);
        CGEventPost(kCGHIDEventTap, event3);
        CFRelease(event3);
        
        [NSThread sleepForTimeInterval: 1];
        
        // SHIFT KEY RELEASE
        CGEventRef event4 = CGEventCreateKeyboardEvent(source,(CGKeyCode)56, NO);
        flags = CGEventSourceFlagsState(kCGEventSourceStateHIDSystemState);
        NSLog(@"Shift up flag %llu \n", flags);
        CGEventPost(kCGHIDEventTap, event4);
        CFRelease(event4);
        
        [NSThread sleepForTimeInterval: 1];
        
        if (source != NULL) {
          CFRelease(source);
        }

        [[NSApplication sharedApplication] terminate:nil];
        [app run];

        return 0;
    }
}
