5 // Created by Yifeng Huang on 7/27/12.
6 // Copyright (c) 2012 __MyCompanyName__. All rights reserved.
9 #import "TargetMouseBtn.h"
11 @implementation TargetMouseBtn
15 + (NSString *)serializationCode {
19 - (NSDictionary *)serialize {
20 return @{ @"type": @"mbtn", @"which": @(self.which) };
23 + (Target *)targetDeserialize:(NSDictionary *)serialization
24 withConfigs:(NSArray *)configs {
25 TargetMouseBtn *target = [[TargetMouseBtn alloc] init];
26 target.which = [serialization[@"which"] intValue];
31 NSRect screenRect = [[NSScreen mainScreen] frame];
32 NSInteger height = screenRect.size.height;
33 NSPoint mouseLoc = [NSEvent mouseLocation];
34 CGEventType eventType = (which == kCGMouseButtonLeft) ? kCGEventLeftMouseDown : kCGEventRightMouseDown;
35 CGEventRef click = CGEventCreateMouseEvent(NULL,
37 CGPointMake(mouseLoc.x, height - mouseLoc.y),
39 CGEventPost(kCGHIDEventTap, click);
44 NSRect screenRect = [[NSScreen mainScreen] frame];
45 NSInteger height = screenRect.size.height;
46 NSPoint mouseLoc = [NSEvent mouseLocation];
47 CGEventType eventType = (which == kCGMouseButtonLeft) ? kCGEventLeftMouseUp : kCGEventRightMouseUp;
48 CGEventRef click = CGEventCreateMouseEvent(NULL,
50 CGPointMake(mouseLoc.x, height - mouseLoc.y),
52 CGEventPost(kCGHIDEventTap, click);