X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=Classes%2FNJOutputMouseButton.m;h=e01e76372f2bbfe42bb890c0604593b69c42d411;hp=bc286bd35b4b82047acc5a2d764fd81184c24bb3;hb=b14d8429658dd6f3f7b4904301031addb502b22c;hpb=7ff376bdcba7d7e8cfe85f9aed863f2254207c7a diff --git a/Classes/NJOutputMouseButton.m b/Classes/NJOutputMouseButton.m index bc286bd..e01e763 100644 --- a/Classes/NJOutputMouseButton.m +++ b/Classes/NJOutputMouseButton.m @@ -37,7 +37,7 @@ } + (NJOutput *)outputDeserialize:(NSDictionary *)serialization - withMappings:(NSArray *)mappings { + withMappings:(id )mappings { NJOutputMouseButton *output = [[NJOutputMouseButton alloc] init]; output.button = [serialization[@"button"] intValue]; return output; @@ -46,31 +46,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);