X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=Classes%2FNJOutputMouseButton.m;fp=Classes%2FNJOutputMouseButton.m;h=bc286bd35b4b82047acc5a2d764fd81184c24bb3;hp=18d82ff99b05fe76b41dfb9332f684a0138feadd;hb=7ff376bdcba7d7e8cfe85f9aed863f2254207c7a;hpb=abe3d190a6388da35ee54c9ab4ef4b56e45045c1 diff --git a/Classes/NJOutputMouseButton.m b/Classes/NJOutputMouseButton.m index 18d82ff..bc286bd 100644 --- a/Classes/NJOutputMouseButton.m +++ b/Classes/NJOutputMouseButton.m @@ -10,6 +10,7 @@ @implementation NJOutputMouseButton { NSDate *upTime; int clickCount; + NSPoint clickPosition; } + (NSTimeInterval)doubleClickInterval { @@ -51,8 +52,8 @@ 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(NSEvent.mouseLocation, clickPosition)) clickCount = 1; else ++clickCount; @@ -63,17 +64,17 @@ } - (void)untrigger { + upTime = [NJOutputMouseButton dateWithClickInterval]; + clickPosition = NSEvent.mouseLocation; CGFloat height = NSScreen.mainScreen.frame.size.height; - NSPoint mouseLoc = NSEvent.mouseLocation; CGEventType eventType = (_button == kCGMouseButtonLeft) ? kCGEventLeftMouseUp : kCGEventRightMouseUp; CGEventRef click = CGEventCreateMouseEvent(NULL, eventType, - CGPointMake(mouseLoc.x, height - mouseLoc.y), + CGPointMake(clickPosition.x, height - clickPosition.y), _button); CGEventSetIntegerValueField(click, kCGMouseEventClickState, clickCount); CGEventPost(kCGHIDEventTap, click); CFRelease(click); - upTime = [NJOutputMouseButton dateWithClickInterval]; } @end