X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=TargetMouseBtn.m;h=3efb88a95fab47472647a2d9be5c6c7139dc90a1;hp=e8d77e42f6c67364557d835ef860a0e00d4383bd;hb=15a3aec049658f4a1c3c6e8c9f8a549fb8de0782;hpb=51d43664909060e85c943c4d63cc3cff307ceb1d diff --git a/TargetMouseBtn.m b/TargetMouseBtn.m index e8d77e4..3efb88a 100644 --- a/TargetMouseBtn.m +++ b/TargetMouseBtn.m @@ -10,16 +10,18 @@ @implementation TargetMouseBtn -@synthesize which; ++ (NSString *)serializationCode { + return @"mbtn"; +} --(NSString*) stringify { - return [[NSString alloc] initWithFormat: @"mbtn~%u", which]; +- (NSDictionary *)serialize { + return @{ @"type": @"mbtn", @"button": @(_button) }; } -+(TargetMouseBtn*) unstringifyImpl: (NSArray*) comps { - NSParameterAssert([comps count] == 2); - TargetMouseBtn* target = [[TargetMouseBtn alloc] init]; - [target setWhich: [comps[1] integerValue]]; ++ (Target *)targetDeserialize:(NSDictionary *)serialization + withConfigs:(NSArray *)configs { + TargetMouseBtn *target = [[TargetMouseBtn alloc] init]; + target.button = [serialization[@"button"] intValue]; return target; } @@ -27,11 +29,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 +42,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); }