X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=TargetMouseBtn.m;h=a19b484475ccf42fcde78a435834279e4247676b;hp=5137f2be5cf4001f92ff1494c683090ff2f5de34;hb=e2a4d830dd9817f6a515a3b1b6aa152d3bb98c2b;hpb=530009447c5bbd360ac5023979cffc6d32a28df3 diff --git a/TargetMouseBtn.m b/TargetMouseBtn.m index 5137f2b..a19b484 100644 --- a/TargetMouseBtn.m +++ b/TargetMouseBtn.m @@ -3,44 +3,47 @@ // Enjoy // // Created by Yifeng Huang on 7/27/12. -// Copyright (c) 2012 __MyCompanyName__. All rights reserved. // #import "TargetMouseBtn.h" @implementation TargetMouseBtn -@synthesize which; ++ (NSString *)serializationCode { + return @"mbtn"; +} --(NSString*) stringify { - return [[NSString alloc] initWithFormat: @"mbtn~%d", which]; +- (NSDictionary *)serialize { + return @{ @"type": @"mbtn", @"button": @(_button) }; } -+(TargetMouseBtn*) unstringifyImpl: (NSArray*) comps { - NSParameterAssert([comps count] == 2); - TargetMouseBtn* target = [[TargetMouseBtn alloc] init]; - [target setWhich: [[comps objectAtIndex:1] integerValue]]; ++ (Target *)targetDeserialize:(NSDictionary *)serialization + withMappings:(NSArray *)mappings { + TargetMouseBtn *target = [[TargetMouseBtn alloc] init]; + target.button = [serialization[@"button"] intValue]; return target; } -(void) trigger { - NSPoint mouseLoc = [NSEvent mouseLocation]; - CGEventType eventType = (which == kCGMouseButtonLeft) ? kCGEventLeftMouseDown : kCGEventRightMouseDown; + CGFloat height = NSScreen.mainScreen.frame.size.height; + NSPoint mouseLoc = NSEvent.mouseLocation; + CGEventType eventType = (_button == kCGMouseButtonLeft) ? kCGEventLeftMouseDown : kCGEventRightMouseDown; CGEventRef click = CGEventCreateMouseEvent(NULL, eventType, - CGPointMake(mouseLoc.x, mouseLoc.y), - which); + CGPointMake(mouseLoc.x, height - mouseLoc.y), + _button); CGEventPost(kCGHIDEventTap, click); CFRelease(click); } -(void) untrigger { - NSPoint mouseLoc = [NSEvent mouseLocation]; - CGEventType eventType = (which == kCGMouseButtonLeft) ? kCGEventLeftMouseUp : kCGEventRightMouseUp; + CGFloat height = NSScreen.mainScreen.frame.size.height; + NSPoint mouseLoc = NSEvent.mouseLocation; + CGEventType eventType = (_button == kCGMouseButtonLeft) ? kCGEventLeftMouseUp : kCGEventRightMouseUp; CGEventRef click = CGEventCreateMouseEvent(NULL, eventType, - CGPointMake(mouseLoc.x, mouseLoc.y), - which); + CGPointMake(mouseLoc.x, height - mouseLoc.y), + _button); CGEventPost(kCGHIDEventTap, click); CFRelease(click); }