{DELAY} now get corret values assinged

This commit is contained in:
michael starke
2014-08-21 00:29:46 +02:00
parent 9458c5f8a0
commit e20e6419fc
2 changed files with 36 additions and 10 deletions

View File

@@ -166,24 +166,47 @@
+ (void)appendCommandForString:(NSString *)commandString toCommands:(NSMutableArray *)commands activeModifer:(CGEventFlags)flags {
if(nil == commandString) {
return;
return; // Nothing to parse
}
/* TODO: Test for special Commands */
/* TODO: fall back to paste if nothing matches */
NSString *delayPrefix = [[NSString alloc] initWithFormat:@"{%@", kKPKAutotypeDelay];
/* Simple Special Press */
NSNumber *keyCodeNumber = [self keypressCommands][commandString];
if(nil != keyCodeNumber) {
CGKeyCode keyCode = [keyCodeNumber keyCodeValue];
[commands addObject:[[MPAutotypeKeyPress alloc] initWithModifierMask:flags keyCode:keyCode]];
return; // Done
}
else if([kKPKAutotypeClearField isEqualToString:commandString]) {
/* Clearfield */
if([kKPKAutotypeClearField isEqualToString:commandString]) {
[commands addObject:[[MPAutotypeClear alloc] init]];
return; // Done
}
else if([commandString hasPrefix:delayPrefix]){
[commands addObject:[[MPAutotypeDelay alloc] initWithDelay:5]];
/* TODO: find the delay */
// TODO: add {APPLICATION <appname>}
/* Delay */
NSString *delayPattern = [[NSString alloc] initWithFormat:@"\\{(%@|%@|)[:|=]+([0-9])+\\}",
kKPKAutotypeDelay,
kKPKAutotypeVirtualKey/*,
kKPKAutotypeVirtualExtendedKey,
kKPKAutotypeVirtualNonExtendedKey*/];
NSRegularExpression *delayRegExp = [[NSRegularExpression alloc] initWithPattern:delayPattern options:NSRegularExpressionCaseInsensitive error:0];
NSAssert(delayRegExp, @"Regex for delay should work!");
NSTextCheckingResult *result = [delayRegExp firstMatchInString:commandString options:0 range:NSMakeRange(0, [commandString length])];
if(result && (result.numberOfRanges == 3)) {
NSString *command = [commandString substringWithRange:[result rangeAtIndex:1]];
NSString *valueString = [commandString substringWithRange:[result rangeAtIndex:2]];
NSScanner *numberScanner = [[NSScanner alloc] initWithString:valueString];
NSInteger value;
if([numberScanner scanInteger:&value]) {
if([kKPKAutotypeDelay isEqualToString:command]) {
[commands addObject:[[MPAutotypeDelay alloc] initWithDelay:value]];
return; // Done
}
else if([kKPKAutotypeVirtualKey isEqualToString:command]) {
// TODO add key
}
}
else {
NSLog(@"Unable to determine delay!");
}
}
else {
[self appendPasteCommandForContent:commandString toCommands:commands];

View File

@@ -56,6 +56,9 @@
XCTAssert([commands[2] isKindOfClass:[MPAutotypePaste class]]);
XCTAssert([commands[3] isKindOfClass:[MPAutotypeKeyPress class]]);
context = [[MPAutotypeContext alloc] initWithEntry:entry andSequence:@"{DELAY=5}{VKEY-NX 1}{VKEY-EX 200}{DELAY 5}{VKEY 300}"];
commands = [MPAutotypeCommand commandsForContext:context];
context = [[MPAutotypeContext alloc] initWithEntry:entry andSequence:@"^T{USERNAME}%+^{TAB}Whoo{PASSWORD}{ENTER}"];
commands = [MPAutotypeCommand commandsForContext:context];