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