X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=NJOutputMouseMove.m;h=4cafb1c58be70e2ad99c0a8792c751588d903149;hp=5e59d4e8b988aa0fec98dba70459fb5c88103afa;hb=72a9fcd1e832a4e22f02018b855feaa414ae8c5c;hpb=dcedf147ddcb6c21768cea94a2f06b93007d2a82 diff --git a/NJOutputMouseMove.m b/NJOutputMouseMove.m index 5e59d4e..4cafb1c 100644 --- a/NJOutputMouseMove.m +++ b/NJOutputMouseMove.m @@ -7,11 +7,9 @@ #import "NJOutputMouseMove.h" -#import "NJInputController.h" +#import "NJDeviceController.h" -@implementation NJOutputMouseMove { - int sign; -} +@implementation NJOutputMouseMove -(BOOL) isContinuous { return YES; @@ -22,41 +20,43 @@ } - (NSDictionary *)serialize { - return @{ @"type": @"mouse move", @"axis": @(_axis) }; + return @{ @"type": self.class.serializationCode, + @"axis": @(_axis), + @"speed": @(_speed), + }; } + (NJOutput *)outputDeserialize:(NSDictionary *)serialization withMappings:(NSArray *)mappings { NJOutputMouseMove *output = [[NJOutputMouseMove alloc] init]; output.axis = [serialization[@"axis"] intValue]; + output.speed = [serialization[@"speed"] floatValue]; + if (!output.speed) + output.speed = 4; return output; } -- (BOOL)update:(NJInputController *)jc { - if (fabsf(self.magnitude) < 0.01) { - sign = 0; +- (BOOL)update:(NJDeviceController *)jc { + if (self.magnitude < 0.05) return NO; // dead zone - } - - // If the input crossed over High/Low, this output is done. - if (!sign) - sign = self.magnitude < 0 ? -1 : 1; - else if (sign / self.magnitude < 0) { - sign = 0; - return NO; - } CGFloat height = NSScreen.mainScreen.frame.size.height; - // TODO - float speed = 4.f; - if (jc.frontWindowOnly) - speed = 12.f; float dx = 0.f, dy = 0.f; - if (_axis == 0) - dx = self.magnitude * speed; - else - dy = self.magnitude * speed; + switch (_axis) { + case 0: + dx = -self.magnitude * _speed; + break; + case 1: + dx = self.magnitude * _speed; + break; + case 2: + dy = -self.magnitude * _speed; + break; + case 3: + dy = self.magnitude * _speed; + break; + } NSPoint mouseLoc = jc.mouseLoc; mouseLoc.x += dx; mouseLoc.y -= dy; @@ -68,16 +68,7 @@ CGEventSetType(move, kCGEventMouseMoved); CGEventSetIntegerValueField(move, kCGMouseEventDeltaX, (int)dx); CGEventSetIntegerValueField(move, kCGMouseEventDeltaY, (int)dy); - - if (jc.frontWindowOnly) { - ProcessSerialNumber psn; - GetFrontProcess(&psn); - CGEventPostToPSN(&psn, move); - } - else { - CGEventPost(kCGHIDEventTap, move); - } - + CGEventPost(kCGHIDEventTap, move); CFRelease(move); return YES; }