5 // Created by Sam McCall on 5/05/09.
8 #import "NJOutputKeyPress.h"
10 #import "NJKeyInputField.h"
12 @implementation NJOutputKeyPress
14 + (NSString *)serializationCode {
18 - (NSDictionary *)serialize {
19 return _vk != NJKeyInputFieldEmpty
20 ? @{ @"type": self.class.serializationCode, @"key": @(_vk) }
24 + (NJOutput *)outputDeserialize:(NSDictionary *)serialization
25 withMappings:(NSArray *)mappings {
26 NJOutputKeyPress *output = [[NJOutputKeyPress alloc] init];
27 output.vk = [serialization[@"key"] intValue];
32 CGEventRef keyDown = CGEventCreateKeyboardEvent(NULL, _vk, YES);
33 CGEventPost(kCGHIDEventTap, keyDown);
38 CGEventRef keyUp = CGEventCreateKeyboardEvent(NULL, _vk, NO);
39 CGEventPost(kCGHIDEventTap, keyUp);