X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=Classes%2FNJOutputMouseButton.m;h=5ddb69d52ac5e0e1737544609e8eff2f35aab1b7;hp=18d82ff99b05fe76b41dfb9332f684a0138feadd;hb=1d9578185de7fb08cf1f4b1e42812e87d8e18040;hpb=abe3d190a6388da35ee54c9ab4ef4b56e45045c1 diff --git a/Classes/NJOutputMouseButton.m b/Classes/NJOutputMouseButton.m index 18d82ff..5ddb69d 100644 --- a/Classes/NJOutputMouseButton.m +++ b/Classes/NJOutputMouseButton.m @@ -10,6 +10,7 @@ @implementation NJOutputMouseButton { NSDate *upTime; int clickCount; + NSPoint clickPosition; } + (NSTimeInterval)doubleClickInterval { @@ -45,27 +46,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 +79,6 @@ CGEventSetIntegerValueField(click, kCGMouseEventClickState, clickCount); CGEventPost(kCGHIDEventTap, click); CFRelease(click); - upTime = [NJOutputMouseButton dateWithClickInterval]; } @end