X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=Classes%2FNJOutputMouseButton.m;h=0b039d108d2eaef2821eb6e2ba94b9cff6e28cb0;hp=18d82ff99b05fe76b41dfb9332f684a0138feadd;hb=24bdb92798b9abe86c7954042a47523791736b7c;hpb=abe3d190a6388da35ee54c9ab4ef4b56e45045c1 diff --git a/Classes/NJOutputMouseButton.m b/Classes/NJOutputMouseButton.m index 18d82ff..0b039d1 100644 --- a/Classes/NJOutputMouseButton.m +++ b/Classes/NJOutputMouseButton.m @@ -10,6 +10,7 @@ @implementation NJOutputMouseButton { NSDate *upTime; int clickCount; + NSPoint clickPosition; } + (NSTimeInterval)doubleClickInterval { @@ -35,8 +36,7 @@ return @{ @"type": self.class.serializationCode, @"button": @(_button) }; } -+ (NJOutput *)outputDeserialize:(NSDictionary *)serialization - withMappings:(NSArray *)mappings { ++ (NJOutput *)outputDeserialize:(NSDictionary *)serialization { NJOutputMouseButton *output = [[NJOutputMouseButton alloc] init]; output.button = [serialization[@"button"] intValue]; return output; @@ -45,27 +45,32 @@ - (void)trigger { CGFloat height = NSScreen.mainScreen.frame.size.height; NSPoint mouseLoc = NSEvent.mouseLocation; - CGEventType eventType = (_button == kCGMouseButtonLeft) ? kCGEventLeftMouseDown : kCGEventRightMouseDown; + CGEventType eventType = _button == kCGMouseButtonLeft ? kCGEventLeftMouseDown + : _button == kCGMouseButtonRight ? kCGEventRightMouseDown + : kCGEventOtherMouseDown; CGEventRef click = CGEventCreateMouseEvent(NULL, eventType, CGPointMake(mouseLoc.x, height - mouseLoc.y), _button); - NSLog(@"%@\n%@", upTime, [NSDate date]); - if (clickCount >= 3 || [upTime compare:[NSDate date]] == NSOrderedAscending) + if (clickCount >= 3 || [upTime compare:[NSDate date]] == NSOrderedAscending + || !CGPointEqualToPoint(mouseLoc, clickPosition)) clickCount = 1; else ++clickCount; CGEventSetIntegerValueField(click, kCGMouseEventClickState, clickCount); - CGEventPost(kCGHIDEventTap, click); CFRelease(click); + clickPosition = mouseLoc; } - (void)untrigger { - CGFloat height = NSScreen.mainScreen.frame.size.height; + upTime = [NJOutputMouseButton dateWithClickInterval]; NSPoint mouseLoc = NSEvent.mouseLocation; - CGEventType eventType = (_button == kCGMouseButtonLeft) ? kCGEventLeftMouseUp : kCGEventRightMouseUp; + CGFloat height = NSScreen.mainScreen.frame.size.height; + CGEventType eventType = _button == kCGMouseButtonLeft ? kCGEventLeftMouseUp + : _button == kCGMouseButtonRight ? kCGEventRightMouseUp + : kCGEventOtherMouseUp; CGEventRef click = CGEventCreateMouseEvent(NULL, eventType, CGPointMake(mouseLoc.x, height - mouseLoc.y), @@ -73,7 +78,6 @@ CGEventSetIntegerValueField(click, kCGMouseEventClickState, clickCount); CGEventPost(kCGHIDEventTap, click); CFRelease(click); - upTime = [NJOutputMouseButton dateWithClickInterval]; } @end