mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-17 13:39:40 +00:00
Function keys commands are now processed correctly
This commit is contained in:
@@ -26,6 +26,8 @@
|
|||||||
|
|
||||||
#import <CommonCrypto/CommonCrypto.h>
|
#import <CommonCrypto/CommonCrypto.h>
|
||||||
|
|
||||||
|
static CGKeyCode kMPFunctionKeyCodes[] = { kVK_F1, kVK_F2, kVK_F3, kVK_F4, kVK_F5, kVK_F6, kVK_F7, kVK_F8, kVK_F9, kVK_F10, kVK_F11, kVK_F12, kVK_F13, kVK_F14, kVK_F15, kVK_F16, kVK_F17, kVK_F18, kVK_F19 };
|
||||||
|
|
||||||
@interface NSNumber (AutotypeCommand)
|
@interface NSNumber (AutotypeCommand)
|
||||||
|
|
||||||
- (CGEventFlags)eventFlagsValue;
|
- (CGEventFlags)eventFlagsValue;
|
||||||
@@ -255,6 +257,21 @@
|
|||||||
[commands addObject:[[MPAutotypeKeyPress alloc] initWithModifierMask:flags keyCode:keyCode]];
|
[commands addObject:[[MPAutotypeKeyPress alloc] initWithModifierMask:flags keyCode:keyCode]];
|
||||||
return; // Done
|
return; // Done
|
||||||
}
|
}
|
||||||
|
/* F1-16 */
|
||||||
|
NSRegularExpression *functionKeyRegExp = [[NSRegularExpression alloc] initWithPattern:kKPKAutotypeFunctionMaskRegularExpression options:NSRegularExpressionCaseInsensitive error:0];
|
||||||
|
NSTextCheckingResult *functionResult = [functionKeyRegExp firstMatchInString:commandString options:0 range:NSMakeRange(0, commandString.length)];
|
||||||
|
if(functionResult && functionResult.numberOfRanges == 2) {
|
||||||
|
NSString *numberString = [commandString substringWithRange:[functionResult rangeAtIndex:1]];
|
||||||
|
NSScanner *numberScanner = [[NSScanner alloc] initWithString:numberString];
|
||||||
|
NSInteger functionNumber = 0;
|
||||||
|
if([numberScanner scanInteger:&functionNumber] && functionNumber >= 1 && functionNumber <= 19) {
|
||||||
|
[commands addObject:[[MPAutotypeKeyPress alloc] initWithModifierMask:flags keyCode:kMPFunctionKeyCodes[functionNumber-1]]];
|
||||||
|
return; // Done
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Numpad 0-9 */
|
||||||
|
/* TODO: Numpad is not invariant, mapping is needed */
|
||||||
|
|
||||||
/* Clearfield */
|
/* Clearfield */
|
||||||
if([kKPKAutotypeClearField isEqualToString:uppercaseCommand]) {
|
if([kKPKAutotypeClearField isEqualToString:uppercaseCommand]) {
|
||||||
[commands addObject:[[MPAutotypeClear alloc] init]];
|
[commands addObject:[[MPAutotypeClear alloc] init]];
|
||||||
@@ -262,14 +279,14 @@
|
|||||||
}
|
}
|
||||||
// TODO: add {APPLICATION <appname>}
|
// TODO: add {APPLICATION <appname>}
|
||||||
/* Delay */
|
/* Delay */
|
||||||
NSString *delayPattern = [[NSString alloc] initWithFormat:@"\\{(%@|%@|)[:|=]+([0-9])+\\}",
|
NSString *delayPattern = [[NSString alloc] initWithFormat:@"\\{(%@|%@|)[ |=]+([0-9])+\\}",
|
||||||
kKPKAutotypeDelay,
|
kKPKAutotypeDelay,
|
||||||
kKPKAutotypeVirtualKey/*,
|
kKPKAutotypeVirtualKey/*,
|
||||||
kKPKAutotypeVirtualExtendedKey,
|
kKPKAutotypeVirtualExtendedKey,
|
||||||
kKPKAutotypeVirtualNonExtendedKey*/];
|
kKPKAutotypeVirtualNonExtendedKey*/];
|
||||||
NSRegularExpression *delayRegExp = [[NSRegularExpression alloc] initWithPattern:delayPattern options:NSRegularExpressionCaseInsensitive error:0];
|
NSRegularExpression *delayRegExp = [[NSRegularExpression alloc] initWithPattern:delayPattern options:NSRegularExpressionCaseInsensitive error:0];
|
||||||
NSAssert(delayRegExp, @"Regex for delay should work!");
|
NSAssert(delayRegExp, @"Regex for delay should work!");
|
||||||
NSTextCheckingResult *result = [delayRegExp firstMatchInString:commandString options:0 range:NSMakeRange(0, [commandString length])];
|
NSTextCheckingResult *result = [delayRegExp firstMatchInString:commandString options:0 range:NSMakeRange(0, commandString.length)];
|
||||||
if(result && (result.numberOfRanges == 3)) {
|
if(result && (result.numberOfRanges == 3)) {
|
||||||
NSString *uppercaseCommand = [[commandString substringWithRange:[result rangeAtIndex:1]] uppercaseString];
|
NSString *uppercaseCommand = [[commandString substringWithRange:[result rangeAtIndex:1]] uppercaseString];
|
||||||
NSString *valueString = [commandString substringWithRange:[result rangeAtIndex:2]];
|
NSString *valueString = [commandString substringWithRange:[result rangeAtIndex:2]];
|
||||||
|
|||||||
Reference in New Issue
Block a user