X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=TargetMouseBtn.m;h=2f56f7e1849b5bcdb551ba17360f1076fe5f4260;hp=857de7b090647cc0d3234054143c832b50af1e62;hb=16a7c0a04bd05f4012d5a97a53520802969cfc86;hpb=a71f9eae29ac9df72aa15c2de80f6a82b5aca44e diff --git a/TargetMouseBtn.m b/TargetMouseBtn.m index 857de7b..2f56f7e 100644 --- a/TargetMouseBtn.m +++ b/TargetMouseBtn.m @@ -10,16 +10,20 @@ @implementation TargetMouseBtn -@synthesize which; +@synthesize button; --(NSString*) stringify { - return [[NSString alloc] initWithFormat: @"mbtn~%u", which]; ++ (NSString *)serializationCode { + return @"mbtn"; } -+(TargetMouseBtn*) unstringifyImpl: (NSArray*) comps { - NSParameterAssert([comps count] == 2); - TargetMouseBtn* target = [[TargetMouseBtn alloc] init]; - [target setWhich: [[comps objectAtIndex:1] integerValue]]; +- (NSDictionary *)serialize { + return @{ @"type": @"mbtn", @"button": @(self.button) }; +} + ++ (Target *)targetDeserialize:(NSDictionary *)serialization + withConfigs:(NSArray *)configs { + TargetMouseBtn *target = [[TargetMouseBtn alloc] init]; + target.button = [serialization[@"button"] intValue]; return target; } @@ -27,11 +31,11 @@ NSRect screenRect = [[NSScreen mainScreen] frame]; NSInteger height = screenRect.size.height; NSPoint mouseLoc = [NSEvent mouseLocation]; - CGEventType eventType = (which == kCGMouseButtonLeft) ? kCGEventLeftMouseDown : kCGEventRightMouseDown; + CGEventType eventType = (button == kCGMouseButtonLeft) ? kCGEventLeftMouseDown : kCGEventRightMouseDown; CGEventRef click = CGEventCreateMouseEvent(NULL, eventType, CGPointMake(mouseLoc.x, height - mouseLoc.y), - which); + button); CGEventPost(kCGHIDEventTap, click); CFRelease(click); } @@ -40,11 +44,11 @@ NSRect screenRect = [[NSScreen mainScreen] frame]; NSInteger height = screenRect.size.height; NSPoint mouseLoc = [NSEvent mouseLocation]; - CGEventType eventType = (which == kCGMouseButtonLeft) ? kCGEventLeftMouseUp : kCGEventRightMouseUp; + CGEventType eventType = (button == kCGMouseButtonLeft) ? kCGEventLeftMouseUp : kCGEventRightMouseUp; CGEventRef click = CGEventCreateMouseEvent(NULL, eventType, CGPointMake(mouseLoc.x, height - mouseLoc.y), - which); + button); CGEventPost(kCGHIDEventTap, click); CFRelease(click); }