X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=Classes%2FNJOutputMouseButton.m;h=c9fe0eb13e64de6320b6713b0169ba89331889a9;hp=18d82ff99b05fe76b41dfb9332f684a0138feadd;hb=4dabc5c754efa54adb2dc57063c7294b1c2e4654;hpb=abe3d190a6388da35ee54c9ab4ef4b56e45045c1 diff --git a/Classes/NJOutputMouseButton.m b/Classes/NJOutputMouseButton.m index 18d82ff..c9fe0eb 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,24 @@ CGEventSetIntegerValueField(click, kCGMouseEventClickState, clickCount); CGEventPost(kCGHIDEventTap, click); CFRelease(click); - upTime = [NJOutputMouseButton dateWithClickInterval]; +} + +- (int)humanIndexedButton { + switch (_button) { + case kCGMouseButtonLeft: return 0; + case kCGMouseButtonCenter: return 1; + case kCGMouseButtonRight: return 2; + default: return 0; + } +} + +- (void)setHumanIndexedButton:(int)humanIndexedButton { + switch (humanIndexedButton) { + case 0: _button = kCGMouseButtonLeft; break; + case 1: _button = kCGMouseButtonCenter; break; + case 2: _button = kCGMouseButtonRight; break; + default: _button = kCGMouseButtonLeft; + } } @end