X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=TargetMouseBtn.m;h=2f56f7e1849b5bcdb551ba17360f1076fe5f4260;hp=e8d77e42f6c67364557d835ef860a0e00d4383bd;hb=c262a3d0972ba16257fd24a948ab04f528f80d33;hpb=51d43664909060e85c943c4d63cc3cff307ceb1d diff --git a/TargetMouseBtn.m b/TargetMouseBtn.m index e8d77e4..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[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); }