From abe3d190a6388da35ee54c9ab4ef4b56e45045c1 Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Sat, 9 Mar 2013 13:34:58 +0100 Subject: [PATCH] Send single/double/triple click information with mouse events. --- Classes/NJOutputMouseButton.m | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/Classes/NJOutputMouseButton.m b/Classes/NJOutputMouseButton.m index d5b1f16..18d82ff 100644 --- a/Classes/NJOutputMouseButton.m +++ b/Classes/NJOutputMouseButton.m @@ -7,7 +7,25 @@ #import "NJOutputMouseButton.h" -@implementation NJOutputMouseButton +@implementation NJOutputMouseButton { + NSDate *upTime; + int clickCount; +} + ++ (NSTimeInterval)doubleClickInterval { + static NSTimeInterval s_doubleClickThreshold; + if (!s_doubleClickThreshold) { + s_doubleClickThreshold = [[NSUserDefaults.standardUserDefaults + objectForKey:@"com.apple.mouse.doubleClickThreshold"] floatValue]; + if (s_doubleClickThreshold <= 0) + s_doubleClickThreshold = 1.0; + } + return s_doubleClickThreshold; +} + ++ (NSDate *)dateWithClickInterval { + return [[NSDate alloc] initWithTimeIntervalSinceNow:self.doubleClickInterval]; +} + (NSString *)serializationCode { return @"mouse button"; @@ -32,6 +50,14 @@ eventType, CGPointMake(mouseLoc.x, height - mouseLoc.y), _button); + + NSLog(@"%@\n%@", upTime, [NSDate date]); + if (clickCount >= 3 || [upTime compare:[NSDate date]] == NSOrderedAscending) + clickCount = 1; + else + ++clickCount; + CGEventSetIntegerValueField(click, kCGMouseEventClickState, clickCount); + CGEventPost(kCGHIDEventTap, click); CFRelease(click); } @@ -44,8 +70,10 @@ eventType, CGPointMake(mouseLoc.x, height - mouseLoc.y), _button); + CGEventSetIntegerValueField(click, kCGMouseEventClickState, clickCount); CGEventPost(kCGHIDEventTap, click); CFRelease(click); + upTime = [NJOutputMouseButton dateWithClickInterval]; } @end -- 2.30.2