Skip to content

Instantly share code, notes, and snippets.

@michaelschade
Created August 15, 2014 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelschade/9ccbd190dfb06fd58790 to your computer and use it in GitHub Desktop.
Save michaelschade/9ccbd190dfb06fd58790 to your computer and use it in GitHub Desktop.
#import "MSAppDelegate.h"
@implementation MSAppDelegate
@synthesize lifxContext, lastKeyPress;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
self.lifxContext = [[LFXClient sharedClient] localNetworkContext];
self.lastKeyPress = CACurrentMediaTime();
[NSEvent addGlobalMonitorForEventsMatchingMask:(NSKeyDownMask) handler:^(NSEvent *event){
NSTimeInterval keyPressElapsed = CACurrentMediaTime() - self.lastKeyPress;
NSTimeInterval duration = 0.8 + 40*(keyPressElapsed*keyPressElapsed); //(10*keyPressElapsed - 1)/keyPressElapsed;
if ([event isARepeat]) {
duration = 1.4;
} else if (duration < 0) {
duration = 0;
} else if (duration > 5) {
duration = 5;
}
NSLog(@"Last key press: %f | time elapsed: %f | duration: %f", self.lastKeyPress, keyPressElapsed, duration);
for (LFXLight *light in lifxContext.allLightsCollection.lights) {
LFXHSBKColor *color = [LFXHSBKColor colorWithHue:arc4random()%360 saturation:1.0 brightness:1.0];
[light setColor:color overDuration:duration];
}
self.lastKeyPress = CACurrentMediaTime();
}];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment