X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=TargetMouseBtn.m;h=28fe536345c24fa88f3e490e320b688da0504fa1;hp=5137f2be5cf4001f92ff1494c683090ff2f5de34;hb=0a402879ee3beb79bb4d2270f909ad75eead0c96;hpb=530009447c5bbd360ac5023979cffc6d32a28df3 diff --git a/TargetMouseBtn.m b/TargetMouseBtn.m index 5137f2b..28fe536 100644 --- a/TargetMouseBtn.m +++ b/TargetMouseBtn.m @@ -12,34 +12,42 @@ @synthesize which; --(NSString*) stringify { - return [[NSString alloc] initWithFormat: @"mbtn~%d", 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", @"which": @(self.which) }; +} + ++ (Target *)targetDeserialize:(NSDictionary *)serialization + withConfigs:(NSArray *)configs { + TargetMouseBtn *target = [[TargetMouseBtn alloc] init]; + target.which = [serialization[@"which"] 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; CGEventRef click = CGEventCreateMouseEvent(NULL, eventType, - CGPointMake(mouseLoc.x, mouseLoc.y), + CGPointMake(mouseLoc.x, height - mouseLoc.y), which); 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; CGEventRef click = CGEventCreateMouseEvent(NULL, eventType, - CGPointMake(mouseLoc.x, mouseLoc.y), + CGPointMake(mouseLoc.x, height - mouseLoc.y), which); CGEventPost(kCGHIDEventTap, click); CFRelease(click);