2 // NJOutputMouseButton.m
5 // Created by Yifeng Huang on 7/27/12.
8 #import "NJOutputMouseButton.h"
10 @implementation NJOutputMouseButton
12 + (NSString *)serializationCode {
13 return @"mouse button";
16 - (NSDictionary *)serialize {
17 return @{ @"type": self.class.serializationCode, @"button": @(_button) };
20 + (NJOutput *)outputDeserialize:(NSDictionary *)serialization
21 withMappings:(NSArray *)mappings {
22 NJOutputMouseButton *output = [[NJOutputMouseButton alloc] init];
23 output.button = [serialization[@"button"] intValue];
28 CGFloat height = NSScreen.mainScreen.frame.size.height;
29 NSPoint mouseLoc = NSEvent.mouseLocation;
30 CGEventType eventType = (_button == kCGMouseButtonLeft) ? kCGEventLeftMouseDown : kCGEventRightMouseDown;
31 CGEventRef click = CGEventCreateMouseEvent(NULL,
33 CGPointMake(mouseLoc.x, height - mouseLoc.y),
35 CGEventPost(kCGHIDEventTap, click);
40 CGFloat height = NSScreen.mainScreen.frame.size.height;
41 NSPoint mouseLoc = NSEvent.mouseLocation;
42 CGEventType eventType = (_button == kCGMouseButtonLeft) ? kCGEventLeftMouseUp : kCGEventRightMouseUp;
43 CGEventRef click = CGEventCreateMouseEvent(NULL,
45 CGPointMake(mouseLoc.x, height - mouseLoc.y),
47 CGEventPost(kCGHIDEventTap, click);