X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=Classes%2FNJOutputMouseButton.m;h=0b039d108d2eaef2821eb6e2ba94b9cff6e28cb0;hp=bc286bd35b4b82047acc5a2d764fd81184c24bb3;hb=24bdb92798b9abe86c7954042a47523791736b7c;hpb=7ff376bdcba7d7e8cfe85f9aed863f2254207c7a diff --git a/Classes/NJOutputMouseButton.m b/Classes/NJOutputMouseButton.m index bc286bd..0b039d1 100644 --- a/Classes/NJOutputMouseButton.m +++ b/Classes/NJOutputMouseButton.m @@ -36,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; @@ -46,31 +45,35 @@ - (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); if (clickCount >= 3 || [upTime compare:[NSDate date]] == NSOrderedAscending - || !CGPointEqualToPoint(NSEvent.mouseLocation, clickPosition)) + || !CGPointEqualToPoint(mouseLoc, clickPosition)) clickCount = 1; else ++clickCount; CGEventSetIntegerValueField(click, kCGMouseEventClickState, clickCount); - CGEventPost(kCGHIDEventTap, click); CFRelease(click); + clickPosition = mouseLoc; } - (void)untrigger { upTime = [NJOutputMouseButton dateWithClickInterval]; - clickPosition = NSEvent.mouseLocation; + NSPoint mouseLoc = NSEvent.mouseLocation; CGFloat height = NSScreen.mainScreen.frame.size.height; - CGEventType eventType = (_button == kCGMouseButtonLeft) ? kCGEventLeftMouseUp : kCGEventRightMouseUp; + CGEventType eventType = _button == kCGMouseButtonLeft ? kCGEventLeftMouseUp + : _button == kCGMouseButtonRight ? kCGEventRightMouseUp + : kCGEventOtherMouseUp; CGEventRef click = CGEventCreateMouseEvent(NULL, eventType, - CGPointMake(clickPosition.x, height - clickPosition.y), + CGPointMake(mouseLoc.x, height - mouseLoc.y), _button); CGEventSetIntegerValueField(click, kCGMouseEventClickState, clickCount); CGEventPost(kCGHIDEventTap, click);