5 // Created by Yifeng Huang on 7/27/12.
8 #import "TargetMouseBtn.h"
10 @implementation TargetMouseBtn
12 + (NSString *)serializationCode {
16 - (NSDictionary *)serialize {
17 return @{ @"type": @"mbtn", @"button": @(_button) };
20 + (Target *)targetDeserialize:(NSDictionary *)serialization
21 withConfigs:(NSArray *)configs {
22 TargetMouseBtn *target = [[TargetMouseBtn alloc] init];
23 target.button = [serialization[@"button"] intValue];
28 NSRect screenRect = [[NSScreen mainScreen] frame];
29 CGFloat height = screenRect.size.height;
30 NSPoint mouseLoc = [NSEvent mouseLocation];
31 CGEventType eventType = (_button == kCGMouseButtonLeft) ? kCGEventLeftMouseDown : kCGEventRightMouseDown;
32 CGEventRef click = CGEventCreateMouseEvent(NULL,
34 CGPointMake(mouseLoc.x, height - mouseLoc.y),
36 CGEventPost(kCGHIDEventTap, click);
41 NSRect screenRect = [[NSScreen mainScreen] frame];
42 CGFloat height = screenRect.size.height;
43 NSPoint mouseLoc = [NSEvent mouseLocation];
44 CGEventType eventType = (_button == kCGMouseButtonLeft) ? kCGEventLeftMouseUp : kCGEventRightMouseUp;
45 CGEventRef click = CGEventCreateMouseEvent(NULL,
47 CGPointMake(mouseLoc.x, height - mouseLoc.y),
49 CGEventPost(kCGHIDEventTap, click);