X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=TargetMouseBtn.m;h=a19b484475ccf42fcde78a435834279e4247676b;hp=2f56f7e1849b5bcdb551ba17360f1076fe5f4260;hb=e2a4d830dd9817f6a515a3b1b6aa152d3bb98c2b;hpb=16a7c0a04bd05f4012d5a97a53520802969cfc86 diff --git a/TargetMouseBtn.m b/TargetMouseBtn.m index 2f56f7e..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 button; - + (NSString *)serializationCode { return @"mbtn"; } - (NSDictionary *)serialize { - return @{ @"type": @"mbtn", @"button": @(self.button) }; + return @{ @"type": @"mbtn", @"button": @(_button) }; } + (Target *)targetDeserialize:(NSDictionary *)serialization - withConfigs:(NSArray *)configs { + withMappings:(NSArray *)mappings { TargetMouseBtn *target = [[TargetMouseBtn alloc] init]; 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 = (button == 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), - button); + _button); CGEventPost(kCGHIDEventTap, click); CFRelease(click); } -(void) untrigger { - NSRect screenRect = [[NSScreen mainScreen] frame]; - NSInteger height = screenRect.size.height; - NSPoint mouseLoc = [NSEvent mouseLocation]; - CGEventType eventType = (button == 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), - button); + _button); CGEventPost(kCGHIDEventTap, click); CFRelease(click); }