Created
November 16, 2018 19:26
-
-
Save jmercouris/8b9c52306ef107778819a4dd31d24f7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Copyright © 2017-2018 Atlas Engineer LLC. | |
// Use of this file is governed by the license that can be found in LICENSE. | |
// | |
#import "NextApplication.h" | |
#include <xmlrpc-c/base.h> | |
#include <xmlrpc-c/client.h> | |
#include <xmlrpc-c/config.h> | |
#include "Global.h" | |
#include "Event.h" | |
@implementation NextApplication | |
- (void)sendEvent:(Event *)event | |
{ | |
Event* _event = [[Event alloc] initWithEvent: event]; | |
if ([_event type] == NSEventTypeKeyDown && [_event consumed] != 1) { | |
NSEventModifierFlags modifierFlags = [_event modifierFlags]; | |
char characterCodePressed = [[_event charactersIgnoringModifiers] characterAtIndex: 0]; | |
bool controlPressed = (modifierFlags & NSEventModifierFlagControl); | |
bool alternatePressed = (modifierFlags & NSEventModifierFlagOption); | |
bool commandPressed = (modifierFlags & NSEventModifierFlagCommand); | |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ | |
xmlrpc_env env = [[Global sharedInstance] getXMLRPCEnv]; | |
const char * const serverUrl = "http://localhost:8081/RPC2"; | |
const char * const methodName = "PUSH-KEY-CHORD"; | |
// Make the remote procedure call | |
xmlrpc_client_call(&env, serverUrl, methodName, | |
"(bbbi)", | |
(xmlrpc_bool) controlPressed, | |
(xmlrpc_bool) alternatePressed, | |
(xmlrpc_bool) commandPressed, | |
(xmlrpc_int) characterCodePressed); | |
dispatch_sync(dispatch_get_main_queue(), ^{ | |
[_event setConsumed:1]; | |
[super sendEvent:_event]; | |
}); | |
}); | |
} else { | |
[super sendEvent:_event]; | |
} | |
} | |
@end | |
// | |
// Copyright © 2017-2018 Atlas Engineer LLC. | |
// Use of this file is governed by the license that can be found in LICENSE. | |
// | |
#import <Cocoa/Cocoa.h> | |
NS_ASSUME_NONNULL_BEGIN | |
@interface Event : NSEvent | |
@property (atomic, readwrite) NSInteger consumed; | |
-(instancetype)initWithEvent:(NSEvent *)event; | |
@end | |
NS_ASSUME_NONNULL_END | |
// | |
// Copyright © 2017-2018 Atlas Engineer LLC. | |
// Use of this file is governed by the license that can be found in LICENSE. | |
// | |
#import "Event.h" | |
@implementation Event | |
@synthesize consumed; | |
-(instancetype)initWithEvent:(NSEvent *)event { | |
self = (Event *)[Event eventWithCGEvent:[event CGEvent]]; | |
if (self) | |
{ | |
[self setConsumed:0]; | |
} | |
return self; | |
} | |
@end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment