Here's the output(on the Xcode debugger) I get from doing the following
leftclick
rightclick
"a" key
"b" key
"c" key
scroll up
scroll up
scroll down
scroll down
scroll down
drag(leftclick)
drag(leftclick)
drag(rightclick)
drag(rightclick)
drag(rightclick)
rightclick
rightclick
insert floppy disk on left side
remove floppy disk on left side:
ComputerCraft[16374:8296782] Click With Button: 1 At x: 18 y: 5
ComputerCraft[16374:8296782] label=cs&data=Click With Button: 1 At x: 18 y: 5
ComputerCraft[16374:8296782] Click With Button: 2 At x: 14 y: 10
ComputerCraft[16374:8296782] label=cs&data=Click With Button: 2 At x: 14 y: 10
ComputerCraft[16374:8296782] key pressed with keycode: 30
ComputerCraft[16374:8296782] label=cs&data=key pressed with keycode: 30
ComputerCraft[16374:8296782] key pressed with keycode: 48
ComputerCraft[16374:8296782] label=cs&data=key pressed with keycode: 48
ComputerCraft[16374:8296782] key pressed with keycode: 46
ComputerCraft[16374:8296782] label=cs&data=key pressed with keycode: 46
ComputerCraft[16374:8296782] Scroll in direction: 1 x: 14 y: 10
ComputerCraft[16374:8296782] label=cs&data=Scroll in direction: 1 x: 14 y: 10
ComputerCraft[16374:8296782] Scroll in direction: 1 x: 14 y: 10
ComputerCraft[16374:8296782] label=cs&data=Scroll in direction: 1 x: 14 y: 10
ComputerCraft[16374:8296782] Scroll in direction: -1 x: 14 y: 10
ComputerCraft[16374:8296782] label=cs&data=Scroll in direction: -1 x: 14 y: 10
ComputerCraft[16374:8296782] Scroll in direction: -1 x: 14 y: 10
ComputerCraft[16374:8296782] label=cs&data=Scroll in direction: -1 x: 14 y: 10
ComputerCraft[16374:8296782] Scroll in direction: -1 x: 14 y: 10
ComputerCraft[16374:8296782] label=cs&data=Scroll in direction: -1 x: 14 y: 10
ComputerCraft[16374:8296782] Drag With Button: 1 At x: 22 y: 12
ComputerCraft[16374:8296782] label=cs&data=Drag With Button: 1 At x: 22 y: 12
ComputerCraft[16374:8296782] Drag With Button: 1 At x: 23 y: 12
ComputerCraft[16374:8296782] label=cs&data=Drag With Button: 1 At x: 23 y: 12
ComputerCraft[16374:8296782] Drag With Button: 2 At x: 23 y: 12
ComputerCraft[16374:8296782] label=cs&data=Drag With Button: 2 At x: 23 y: 12
ComputerCraft[16374:8296782] Click With Button: 2 At x: 17 y: 12
ComputerCraft[16374:8296782] label=cs&data=Click With Button: 2 At x: 17 y: 12
ComputerCraft[16374:8296782] Drag With Button: 2 At x: 20 y: 12
ComputerCraft[16374:8296782] label=cs&data=Drag With Button: 2 At x: 20 y: 12
ComputerCraft[16374:8296782] Disk Inserted On Disk Inserted On left Side Side
ComputerCraft[16374:8296782] label=cs&data=Disk Inserted On left Side
ComputerCraft[16374:8296782] Disk Ejected On Disk Ejected On left Side Side
ComputerCraft[16374:8296782] label=cs&data=Disk Ejected On left Side
I'm still working on the actual handling and returns, but what do you think of the concept? I'm also looking for someone else to work with on the project, so if you're interested then please PM me.
Here's the implementation code, if you want it:
Spoiler
There are a couple methods that are there but are either unimplemented or unused, for example-(NSArray *)coordinatesFromString:(NSString *)coordString;
#import "AppDelegate.h"
@interface AppDelegate ()
@property (weak) IBOutlet NSWindow *window;
@end
@implementation AppDelegate
@synthesize parse;
@synthesize parsed;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
}
- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
}
/* Start of HTTP Code */
-(void)sendRequestWithLabel:(NSString *)label data:(NSString *)data{
NSString *postString = [NSString stringWithFormat:@"label=%@&data=%@", label, data];
NSLog(postString);
NSData *postData = [postString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];
NSMutableURLRequest *theRequest = [NSMutableURLRequest new];
[theRequest setURL:[NSURL URLWithString:@"http://www.softberrykai.com/cc/objc.php"]];
[theRequest setHTTPMethod:@"POST"];
[theRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
[theRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[theRequest setHTTPBody:postData];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
recievedData = [NSMutableData data];
}
else {
// Inform the user that the connection failed.
}
}
-(void)sendRequestWithTimer:(NSTimer *)theTimer{
NSString *postString = [NSString stringWithFormat:@"label=%@&data=%@", [[NSString alloc] initWithString:(NSString *)[[theTimer userInfo] objectForKey:@"label"]], [[NSString alloc] initWithString:(NSString *)[[theTimer userInfo] objectForKey:@"data"]]];
NSData *postData = [postString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];
NSMutableURLRequest *theRequest = [NSMutableURLRequest new];
[theRequest setURL:[NSURL URLWithString:@"http://www.softberrykai.com/cc/objc.php"]];
[theRequest setHTTPMethod:@"POST"];
[theRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
[theRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[theRequest setHTTPBody:postData];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
recievedData = [NSMutableData data];
}
else {
// Inform the user that the connection failed.
}
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[recievedData setLength:0];
NSString *receivedDataString = [[NSString alloc] initWithData:recievedData encoding:NSUTF8StringEncoding];
recievedString = receivedDataString;
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
// Append the new data to receivedData.
// receivedData is an instance variable declared elsewhere.
[recievedData appendData:data];
NSString *receivedDataString = [[NSString alloc] initWithData:recievedData encoding:NSUTF8StringEncoding];
[_returnedValue setStringValue:[NSString stringWithFormat:@"Feedback Recieved: '%@'", receivedDataString]];
recievedString = receivedDataString;
[self dataRecieved];
}
/* End of HTTP Code */
-(IBAction)transcieveData:(NSButton *)sender{
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(sendRequestWithTimer:) userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"cr",@"label",@" ",@"data",nil] repeats:YES];
}
-(NSArray *)coordinatesFromString:(NSString *)coordString{
NSRange open = [coordString rangeOfString:@"x"];
NSRange close = [coordString rangeOfString:@"y"];
NSRange nr = NSMakeRange(open.location + 1, close.location - open.location - 1);
NSString *xv = [coordString substringWithRange:nr];
open = [coordString rangeOfString:@"y"];
close = [coordString rangeOfString:@"|"];
nr = NSMakeRange(open.location + 1, close.location - open.location - 1);
NSString *yv = [coordString substringWithRange:nr];
int x = [xv intValue];
int y = [yv intValue];
open = [coordString rangeOfString:@"b"];
close = [coordString rangeOfString:@"c"];
nr = NSMakeRange(open.location + 1, close.location - open.location - 1);
NSString *bs = [coordString substringWithRange:nr];
int b = [bs intValue];
NSArray *coordinates = [NSArray arrayWithObjects:[NSNumber numberWithInt:x], [NSNumber numberWithInt:y], [NSNumber numberWithInt:b], nil];
return coordinates;
}
- (NSArray *)parseString:(NSString *)string withMarkers:(NSArray *)markers {
__block NSMutableArray *returnv = [NSMutableArray new];
__block NSString *first = @"";
__block NSString *second = @"";
[markers enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL *stop){
second = obj;
if ((int)idx != 0) {
NSRange open = [string rangeOfString:first];
NSRange close = [string rangeOfString:second];
NSRange oc = NSMakeRange(open.location + 1, close.location - open.location - 1);
NSString *segment = [string substringWithRange:oc];
[returnv addObject:segment];
}
first = second;
}];
return [returnv copy];
}
-(void)processClickAtX:(int)x Y:(int)y{
}
-(void)dataRecieved{
NSString *s = @"";
if ([recievedString containsString:@"eventclick"]) {
//General Click Handling
self.parse = [NSArray arrayWithObjects:@"b", @"x", @"y", @"|", nil];
parsed = [self parseString:recievedString withMarkers:self.parse];
int b = [[parsed objectAtIndex:0] intValue];
int x = [[parsed objectAtIndex:1] intValue];
int y = [[parsed objectAtIndex:2] intValue];
s = [NSString stringWithFormat:@"Click With Button: %i At x: %i y: %i",b,x,y];
NSLog(@"Click With Button: %i At x: %i y: %i",b,x,y);
[self sendRequestWithLabel:@"cs" data:s];
}
else if ([recievedString containsString:@"eventstartup"]) {
//Initialization
}
else if ([recievedString containsString:@"eventkey"]){
//Handle Key Press
parsed = [self parseString:recievedString withMarkers:[NSArray arrayWithObjects:@"k", @"|", nil]];
int k = [[parsed objectAtIndex:0] intValue];
s = [NSString stringWithFormat:@"key pressed with keycode: %i", k];
NSLog(@"key pressed with keycode: %i", k);
[self sendRequestWithLabel:@"cs" data:s];
}
else if ([recievedString containsString:@"eventscroll"]){
//Handle Scroll
parsed = [self parseString:recievedString withMarkers:[NSArray arrayWithObjects:@"d",@"x",@"y",@"|", nil]];
int d = [[parsed objectAtIndex:0] intValue];
int x = [[parsed objectAtIndex:1] intValue];
int y = [[parsed objectAtIndex:2] intValue];
s = [NSString stringWithFormat:@"Scroll in direction: %i x: %i y: %i",d,x,y];
NSLog(@"Scroll in direction: %i x: %i y: %i",d,x,y);
[self sendRequestWithLabel:@"cs" data:s];
}
else if ([recievedString containsString:@"eventdrag"]){
//Handle Mouse Drag
parsed = [self parseString:recievedString withMarkers:[NSArray arrayWithObjects:@"b", @"x", @"y", @"|", nil]];
int b = [[parsed objectAtIndex:0] intValue];
int x = [[parsed objectAtIndex:1] intValue];
int y = [[parsed objectAtIndex:2] intValue];
s = [NSString stringWithFormat:@"Drag With Button: %i At x: %i y: %i",b,x,y];
NSLog(@"Drag With Button: %i At x: %i y: %i",b,x,y);
[self sendRequestWithLabel:@"cs" data:s];
}
else if ([recievedString containsString:@"eventdiskinsert"]){
//Handle Disk Insertion
parsed = [self parseString:recievedString withMarkers:[NSArray arrayWithObjects:@"s", @"|", nil]];
NSString *s = [parsed objectAtIndex:0];
s = [NSString stringWithFormat:@"Disk Inserted On %@ Side",s];
NSLog(@"Disk Inserted On %@ Side",s);
[self sendRequestWithLabel:@"cs" data:s];
}
else if ([recievedString containsString:@"eventdiskeject"]){
parsed = [self parseString:recievedString withMarkers:[NSArray arrayWithObjects:@"s", @"|", nil]];
NSString *s = [parsed objectAtIndex:0];
s = [NSString stringWithFormat:@"Disk Ejected On %@ Side",s];
NSLog(@"Disk Ejected On %@ Side",s);
[self sendRequestWithLabel:@"cs" data:s];
}
}
-(void)displayArray:(NSArray *)array{
}
@end