From c14bcf497eb452828abbe7b9800731a006b8b40f Mon Sep 17 00:00:00 2001 From: michael starke Date: Thu, 28 Nov 2013 01:42:00 +0100 Subject: [PATCH] Some reshuffling of the Autotype Code. Added preferences key for Ctrl/Command swapping, since this might be a problem in multi platform use cases --- KeePassKit | 2 +- MacPass/MPAutotypeCommand.m | 80 ++++++++++++++++++++++++++++++++++--- MacPass/MPSettingsHelper.h | 3 ++ MacPass/MPSettingsHelper.m | 5 ++- 4 files changed, 83 insertions(+), 7 deletions(-) diff --git a/KeePassKit b/KeePassKit index 6992db36..2b5a795a 160000 --- a/KeePassKit +++ b/KeePassKit @@ -1 +1 @@ -Subproject commit 6992db36111e39e28e83146af2a0a20877670d73 +Subproject commit 2b5a795a4345a95b9ce727b00941ec43a84ecaa9 diff --git a/MacPass/MPAutotypeCommand.m b/MacPass/MPAutotypeCommand.m index 8473707d..608d8c3a 100644 --- a/MacPass/MPAutotypeCommand.m +++ b/MacPass/MPAutotypeCommand.m @@ -70,12 +70,80 @@ + (NSArray *)commandsForCommandString:(NSString *)commands { NSUInteger commandIndex = 0; + CGEventFlags modiferKeys = 0; while(commandIndex <= [commands length]) { - NSString *nextCommand = [commands nextCommandFromIndex:0]; - /* itearte over all comamnds */ - /* determine singel commands, paste, etc */ - /* create command with appropriate initalizers */ - /* return array with ordered commands */ + /* Modifier Keys + Shift + + Ctrl ^ + Alt % + Enter ~ // No modifier! + */ + NSString *currentCommans = [commands substringFromIndex:commandIndex]; + NSCharacterSet *modifierKeySet = [NSCharacterSet characterSetWithCharactersInString:@"+^%"]; + NSRange modifierRange = [currentCommans rangeOfCharacterFromSet:modifierKeySet options:NSCaseInsensitiveSearch range:NSMakeRange(0, 1)]; + if(modifierRange.length != 0 && modifierRange.location == 0) { + /* starts with a special key */ + if([currentCommans hasPrefix:@"+"]) { + modiferKeys |= kCGEventFlagMaskAlphaShift; + } + if([currentCommans hasPrefix:@"^"]) { + modiferKeys |= kCGEventFlagMaskControl; + } + if([currentCommans hasPrefix:@"%"]) { + modiferKeys = kCGEventFlagMaskAlternate; + } + /* move the index and continue */ + commandIndex++; + continue; + } + if([currentCommans hasPrefix:@"{"]) { + NSRange closeBracket = [currentCommans rangeOfString:@"}"]; + if(closeBracket.length == 0) { + NSLog(@"Syntax error in Autotype Sequence %@ at index: %ld", commands, commandIndex); + return nil; + } + } + /* Search on to another bracket or a special key */ + + /* Command Keys + Tab {TAB} + Enter {ENTER} or ~ + Arrow Up {UP} + Arrow Down {DOWN} + Arrow Left {LEFT} + Arrow Right {RIGHT} + Insert {INSERT} or {INS} + Delete {DELETE} or {DEL} + Home {HOME} + End {END} + Page Up {PGUP} + Page Down {PGDN} + Backspace {BACKSPACE}, {BS} or {BKSP} + Break {BREAK} + Caps-Lock {CAPSLOCK} + Escape {ESC} + Windows Key {WIN} (equ. to {LWIN}) + Windows Key: left, right {LWIN}, {RWIN} + Apps / Menu {APPS} + Help {HELP} + Numlock {NUMLOCK} + Print Screen {PRTSC} + Scroll Lock {SCROLLLOCK} + F1 - F16 {F1} - {F16} + Numeric Keypad + {ADD} + Numeric Keypad - {SUBTRACT} + Numeric Keypad * {MULTIPLY} + Numeric Keypad / {DIVIDE} + Numeric Keypad 0 to 9 {NUMPAD0} to {NUMPAD9} + + {+} + ^ {^} + % {%} + ~ {~} + (, ) {(}, {)} + [, ] {[}, {]} + {, } {{}, {}} + + */ } return nil; } @@ -192,6 +260,8 @@ return (CGKeyCode)virtualKeyCode; } + + - (void)execute {} @end diff --git a/MacPass/MPSettingsHelper.h b/MacPass/MPSettingsHelper.h index 5e0dc9d5..b51ca1d1 100644 --- a/MacPass/MPSettingsHelper.h +++ b/MacPass/MPSettingsHelper.h @@ -46,6 +46,9 @@ APPKIT_EXTERN NSString *const kMPSettingsKeyLastKeyURL; APPKIT_EXTERN NSString *const kMPSettingsKeyRememberLastKey; */ +/* Autotype */ +APPKIT_EXTERN NSString *const kMPSettingsKeySendCommandForControlKey; + typedef NS_ENUM(NSUInteger, MPPasswordEncoding) { MPPasswordEncodingUTF8, MPPasswordEncodingASCII, diff --git a/MacPass/MPSettingsHelper.m b/MacPass/MPSettingsHelper.m index 7c6f2184..d6ff3d3d 100644 --- a/MacPass/MPSettingsHelper.m +++ b/MacPass/MPSettingsHelper.m @@ -30,6 +30,8 @@ NSString *const kMPSettingsKeyLastDatabasePath = @"LastDatabasePath"; NSString *const kMPSettingsKeyRememeberdKeysForDatabases = @"RememeberdKeysForDatabases"; NSString *const kMPSettingsKeyRememberKeyFilesForDatabases = @"RememberKeyFilesForDatabases"; +NSString *const kMPSettingsKeySendCommandForControlKey = @"SendCommandKeyForControlKey"; + @implementation MPSettingsHelper + (void)setupDefaults { @@ -58,7 +60,8 @@ NSString *const kMPSettingsKeyRememberKeyFilesForDatabases = @"RememberKeyFilesF kMPSettingsKeyLegacyHideTitle: @NO, kMPSettingsKeyLegacyHideURL: @NO, kMPSettingsKeyLegacyHideUsername: @NO, - kMPSettingsKeyRememberKeyFilesForDatabases: @NO + kMPSettingsKeyRememberKeyFilesForDatabases: @NO, + kMPSettingsKeySendCommandForControlKey: @YES }; }