#import <Cocoa/Cocoa.h>

int main() {
  CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
  CGEventType type = kCGEventMouseMoved;
  volatile CGPoint point;
  point.x = 20000;
  point.y = 200;

  CGMouseButton button = kCGMouseButtonLeft;
  CGEventRef mouseEvent = CGEventCreateMouseEvent(source, type, point, button);
  CGEventSetIntegerValueField(mouseEvent, kCGMouseEventClickState, 0);
  CGEventSetIntegerValueField(mouseEvent, kCGMouseEventNumber, 0);
  CGEventPost(kCGHIDEventTap, mouseEvent);
  CFRelease(mouseEvent);
  CFRelease(source);

  [NSThread sleepForTimeInterval:0.5];

  CGEventRef event = CGEventCreate(NULL);
  CGPoint globalPos = CGEventGetLocation(event);
  CFRelease(event);
  
  NSLog(@"Mouse Location: %@", NSStringFromPoint(globalPos));


  
  [NSThread sleepForTimeInterval:0.5];

  source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
  type = kCGEventLeftMouseDown;
  button = kCGMouseButtonLeft;

  mouseEvent = CGEventCreateMouseEvent(source, type, point, button);
  CGEventSetIntegerValueField(mouseEvent, kCGMouseEventClickState, 0);
  CGEventSetIntegerValueField(mouseEvent, kCGMouseEventNumber, 0);
  CGEventPost(kCGHIDEventTap, mouseEvent);
  CFRelease(mouseEvent);
  CFRelease(source);

  [NSThread sleepForTimeInterval:0.5];
  
  event = CGEventCreate(NULL);
  globalPos = CGEventGetLocation(event);
  CFRelease(event);

  NSLog(@"Mouse Pressed: %@", NSStringFromPoint(globalPos));



  [NSThread sleepForTimeInterval:0.5];

  source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
  type = kCGEventLeftMouseUp;
  button = kCGMouseButtonLeft;

  mouseEvent = CGEventCreateMouseEvent(source, type, point, button);
  CGEventSetIntegerValueField(mouseEvent, kCGMouseEventClickState, 0);
  CGEventSetIntegerValueField(mouseEvent, kCGMouseEventNumber, 0);
  CGEventPost(kCGHIDEventTap, mouseEvent);
  CFRelease(mouseEvent);
  CFRelease(source);

  [NSThread sleepForTimeInterval:0.5];

  event = CGEventCreate(NULL);
  globalPos = CGEventGetLocation(event);
  CFRelease(event);

  NSLog(@"Mouse Released: %@", NSStringFromPoint(globalPos));
}
