X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=TargetMouseBtn.m;h=a19b484475ccf42fcde78a435834279e4247676b;hp=28fe536345c24fa88f3e490e320b688da0504fa1;hb=e2a4d830dd9817f6a515a3b1b6aa152d3bb98c2b;hpb=0a402879ee3beb79bb4d2270f909ad75eead0c96 diff --git a/TargetMouseBtn.m b/TargetMouseBtn.m index 28fe536..a19b484 100644 --- a/TargetMouseBtn.m +++ b/TargetMouseBtn.m @@ -3,52 +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"; } - (NSDictionary *)serialize { - return @{ @"type": @"mbtn", @"which": @(self.which) }; + return @{ @"type": @"mbtn", @"button": @(_button) }; } + (Target *)targetDeserialize:(NSDictionary *)serialization - withConfigs:(NSArray *)configs { + withMappings:(NSArray *)mappings { TargetMouseBtn *target = [[TargetMouseBtn alloc] init]; - target.which = [serialization[@"which"] intValue]; + target.button = [serialization[@"button"] intValue]; return target; } -(void) trigger { - NSRect screenRect = [[NSScreen mainScreen] frame]; - NSInteger height = screenRect.size.height; - 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, height - mouseLoc.y), - which); + _button); CGEventPost(kCGHIDEventTap, click); CFRelease(click); } -(void) untrigger { - NSRect screenRect = [[NSScreen mainScreen] frame]; - NSInteger height = screenRect.size.height; - 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, height - mouseLoc.y), - which); + _button); CGEventPost(kCGHIDEventTap, click); CFRelease(click); }