X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=NJOutputMouseMove.m;h=884a3d3cf8d358c53f9ead6a17d6b10870b03e50;hp=8efb8cb29c174c1708b5b55762e81c0bd9dd3f87;hb=56d825ba259066d847a9fc3f9c8c0c0a362a1507;hpb=844a57be52a2e243832e3d83d148fa3cea6d5ad1 diff --git a/NJOutputMouseMove.m b/NJOutputMouseMove.m index 8efb8cb..884a3d3 100644 --- a/NJOutputMouseMove.m +++ b/NJOutputMouseMove.m @@ -9,54 +9,54 @@ #import "NJDeviceController.h" -@implementation NJOutputMouseMove { - int sign; -} - --(BOOL) isContinuous { - return YES; -} +@implementation NJOutputMouseMove + (NSString *)serializationCode { return @"mouse move"; } - (NSDictionary *)serialize { - return @{ @"type": self.class.serializationCode, @"axis": @(_axis) }; + return @{ @"type": self.class.serializationCode, + @"axis": @(_axis), + @"speed": @(_speed), + }; } + (NJOutput *)outputDeserialize:(NSDictionary *)serialization withMappings:(NSArray *)mappings { - NJOutputMouseMove *output = [[NJOutputMouseMove alloc] init]; + NJOutputMouseMove *output = [[NJOutputMouseMove alloc] init]; output.axis = [serialization[@"axis"] intValue]; - return output; + output.speed = [serialization[@"speed"] floatValue]; + if (!output.speed) + output.speed = 4; + return output; +} + +- (BOOL)isContinuous { + return YES; } - (BOOL)update:(NJDeviceController *)jc { - if (fabsf(self.magnitude) < 0.01) { - sign = 0; + 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; }