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 @{ @"type": @"key press", @"key": @(_vk) };
22 + (NJOutput *)outputDeserialize:(NSDictionary *)serialization
23 withMappings:(NSArray *)mappings {
24 NJOutputKeyPress *output = [[NJOutputKeyPress alloc] init];
25 output.vk = [serialization[@"key"] intValue];
30 CGEventRef keyDown = CGEventCreateKeyboardEvent(NULL, _vk, YES);
31 CGEventPost(kCGHIDEventTap, keyDown);
36 CGEventRef keyUp = CGEventCreateKeyboardEvent(NULL, _vk, NO);
37 CGEventPost(kCGHIDEventTap, keyUp);