X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=Classes%2FNJOutputKeyPress.m;fp=Classes%2FNJOutputKeyPress.m;h=622cf41083d21d58195099567e0e5d81c777459d;hp=0000000000000000000000000000000000000000;hb=0064c1fbff36795885a9724081af2a17d83c20a3;hpb=56d825ba259066d847a9fc3f9c8c0c0a362a1507 diff --git a/Classes/NJOutputKeyPress.m b/Classes/NJOutputKeyPress.m new file mode 100644 index 0000000..622cf41 --- /dev/null +++ b/Classes/NJOutputKeyPress.m @@ -0,0 +1,43 @@ +// +// NJOutputKeyPress.m +// Enjoy +// +// Created by Sam McCall on 5/05/09. +// + +#import "NJOutputKeyPress.h" + +#import "NJKeyInputField.h" + +@implementation NJOutputKeyPress + ++ (NSString *)serializationCode { + return @"key press"; +} + +- (NSDictionary *)serialize { + return _vk != NJKeyInputFieldEmpty + ? @{ @"type": self.class.serializationCode, @"key": @(_vk) } + : nil; +} + ++ (NJOutput *)outputDeserialize:(NSDictionary *)serialization + withMappings:(NSArray *)mappings { + NJOutputKeyPress *output = [[NJOutputKeyPress alloc] init]; + output.vk = [serialization[@"key"] intValue]; + return output; +} + +- (void)trigger { + CGEventRef keyDown = CGEventCreateKeyboardEvent(NULL, _vk, YES); + CGEventPost(kCGHIDEventTap, keyDown); + CFRelease(keyDown); +} + +- (void)untrigger { + CGEventRef keyUp = CGEventCreateKeyboardEvent(NULL, _vk, NO); + CGEventPost(kCGHIDEventTap, keyUp); + CFRelease(keyUp); +} + +@end