Created
November 16, 2018 21:49
-
-
Save jmercouris/a8a3c85f4fe6a3c76c8021bb81ee74d2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// | |
// NextApplication.m | |
// next-cocoa | |
// | |
// Created by John Mercouris on 3/25/18. | |
// Copyright © 2018 Next. All rights reserved. | |
// | |
#import "NextApplication.h" | |
#include <xmlrpc-c/base.h> | |
#include <xmlrpc-c/client.h> | |
#include <xmlrpc-c/config.h> | |
#include "Global.h" | |
@implementation NextApplication | |
- (void)sendEvent:(NSEvent *)event | |
{ | |
if ([event type] == NSEventTypeKeyDown) { | |
NSLog(@"KEYDOWN"); | |
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]; | |
xmlrpc_value * resultP; | |
xmlrpc_int consumed; | |
const char * const serverUrl = "http://localhost:8081/RPC2"; | |
const char * const methodName = "PUSH-KEY-CHORD"; | |
// Make the remote procedure call | |
resultP = xmlrpc_client_call(&env, serverUrl, methodName, | |
"(bbbi)", | |
(xmlrpc_bool) controlPressed, | |
(xmlrpc_bool) alternatePressed, | |
(xmlrpc_bool) commandPressed, | |
(xmlrpc_int) characterCodePressed); | |
xmlrpc_read_int(&env, resultP, &consumed); | |
if (!consumed) { | |
dispatch_sync(dispatch_get_main_queue(), ^{ | |
[super sendEvent:event]; | |
}); | |
} | |
}); | |
} else { | |
[super sendEvent:event]; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment