mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-24 23:09:33 +00:00
Removed AutotypeParser as this is now handled by an NSString Cateogriy in KeePassKit
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
extern NSString *const MPDidChangeStoredKeyFilesSettings;
|
||||
FOUNDATION_EXTERN NSString *const MPDidChangeStoredKeyFilesSettings;
|
||||
|
||||
@interface MPAppDelegate : NSObject <NSApplicationDelegate, NSMenuDelegate>
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
@property (readonly, strong) MPAutotypeContext *context;
|
||||
|
||||
|
||||
+ (NSArray *)commandsForContext:(MPAutotypeContext *)context;
|
||||
/**
|
||||
* Sends a KeyPress Event with the supplied modifier flags and Keycode
|
||||
* Any existing modifiers will be disabled for this event. If the user
|
||||
|
||||
@@ -15,6 +15,12 @@
|
||||
|
||||
@implementation MPAutotypeCommand
|
||||
|
||||
+ (NSArray *)commandsForContext:(MPAutotypeContext *)context {
|
||||
NSError *error;
|
||||
NSRegularExpression *regularExpression = [[NSRegularExpression alloc] initWithPattern:@"" options:0 error:&error];
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)sendPressKey:(CGKeyCode)keyCode modifierFlags:(CGEventFlags)flags {
|
||||
CGEventRef pressKey = CGEventCreateKeyboardEvent (NULL, keyCode, YES);
|
||||
CGEventRef releaseKey = CGEventCreateKeyboardEvent (NULL, keyCode, NO);
|
||||
|
||||
@@ -11,12 +11,20 @@
|
||||
@class KPKEntry;
|
||||
@class KPKWindowAssociation;
|
||||
|
||||
/**
|
||||
* Context for a autotype command run.
|
||||
* It stores the Entry and corresponding sequence to use for autotyping
|
||||
*/
|
||||
@interface MPAutotypeContext : NSObject <NSCopying>
|
||||
|
||||
/**
|
||||
* The entry associated with the command sequence.
|
||||
*/
|
||||
@property (nonatomic, strong) KPKEntry *entry;
|
||||
/**
|
||||
* The command in normalized (see NSString+Commands)
|
||||
*/
|
||||
@property (nonatomic, copy) NSString *command;
|
||||
@property (nonatomic, assign, readonly) BOOL isCommand;
|
||||
@property (nonatomic, assign) NSInteger value;
|
||||
|
||||
/**
|
||||
* Designated initializer
|
||||
|
||||
@@ -11,12 +11,7 @@
|
||||
#import "KPKAutotype.h"
|
||||
#import "KPKEntry.h"
|
||||
#import "KPKWindowAssociation.h"
|
||||
|
||||
@interface MPAutotypeContext ()
|
||||
|
||||
@property (nonatomic, assign) BOOL isCommand;
|
||||
|
||||
@end
|
||||
#import "NSString+Commands.h"
|
||||
|
||||
@implementation MPAutotypeContext
|
||||
|
||||
@@ -32,41 +27,9 @@
|
||||
|
||||
- (instancetype)initWithEntry:(KPKEntry *)entry andSequence:(NSString *)sequence {
|
||||
self = [super init];
|
||||
/*
|
||||
Parse the sequence to determine a possible Value?
|
||||
DELAY <seconds>
|
||||
TAB <repeat>
|
||||
VKEY <code>
|
||||
*/
|
||||
if(self) {
|
||||
if(entry == nil || sequence == nil) {
|
||||
self = nil;
|
||||
}
|
||||
else {
|
||||
self.entry = entry;
|
||||
NSError *error;
|
||||
NSRegularExpression *regexp = [[NSRegularExpression alloc] initWithPattern:@"\\{([a-z]+)?([0-9]*)\\}" options:NSRegularExpressionCaseInsensitive error:&error];
|
||||
if(regexp) {
|
||||
[regexp enumerateMatchesInString:sequence options:0 range:NSMakeRange(0, [sequence length]) usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
|
||||
NSRange commandRange = [result rangeAtIndex:1];
|
||||
NSRange valueRange = [result rangeAtIndex:2];
|
||||
if(commandRange.location != NSNotFound && commandRange.length != 0) {
|
||||
self.command = [sequence substringWithRange:commandRange];
|
||||
self.isCommand = YES;
|
||||
}
|
||||
if(valueRange.location != NSNotFound && valueRange.length != 0) {
|
||||
self.value = [[sequence substringWithRange:valueRange] integerValue];
|
||||
}
|
||||
else {
|
||||
self.value = NSNotFound;
|
||||
}
|
||||
}];
|
||||
}
|
||||
else {
|
||||
NSLog(@"Error while trying to parse Autotype sequence: %@", [error localizedDescription]);
|
||||
}
|
||||
|
||||
}
|
||||
_command = [[sequence normalizedCommand] copy];
|
||||
_entry = entry;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
//
|
||||
// MPAutotypeParser.h
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 28/11/13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface MPAutotypeParser : NSObject
|
||||
|
||||
+ (NSArray *)commandsForCommandString:(NSString *)commands;
|
||||
|
||||
@end
|
||||
@@ -1,110 +0,0 @@
|
||||
//
|
||||
// MPAutotypeParser.m
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 28/11/13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPAutotypeParser.h"
|
||||
|
||||
#import "KPKAutotypeCommands.h"
|
||||
|
||||
@implementation MPAutotypeParser
|
||||
|
||||
+ (NSArray *)commandsForCommandString:(NSString *)commands {
|
||||
NSUInteger commandIndex = 0;
|
||||
CGEventFlags modiferKeys = 0;
|
||||
while(commandIndex <= [commands length]) {
|
||||
/* Modifier Keys
|
||||
Shift +
|
||||
Ctrl ^
|
||||
Alt %
|
||||
*/
|
||||
NSString *currentCommands = [commands substringFromIndex:commandIndex];
|
||||
NSCharacterSet *modifierKeySet = [NSCharacterSet characterSetWithCharactersInString:@"+^%"];
|
||||
NSRange modifierRange = [currentCommands rangeOfCharacterFromSet:modifierKeySet options:NSCaseInsensitiveSearch range:NSMakeRange(0, 1)];
|
||||
if(modifierRange.length != 0 && modifierRange.location == 0) {
|
||||
/* starts with a special key */
|
||||
if([currentCommands hasPrefix:kMPAutotypeShortShift]) {
|
||||
modiferKeys |= kCGEventFlagMaskAlphaShift;
|
||||
}
|
||||
if([currentCommands hasPrefix:kMPAutotypeShortControl]) {
|
||||
modiferKeys |= kCGEventFlagMaskControl;
|
||||
}
|
||||
if([currentCommands hasPrefix:kMPAutotypeShortAlt]) {
|
||||
modiferKeys = kCGEventFlagMaskAlternate;
|
||||
}
|
||||
/* move the index and continue */
|
||||
commandIndex++;
|
||||
continue;
|
||||
}
|
||||
if([currentCommands hasPrefix:@"{"]) {
|
||||
/* Commands reset the modifiers */
|
||||
modiferKeys = 0;
|
||||
NSRange closeBracket = [currentCommands rangeOfString:@"}"];
|
||||
if(closeBracket.length == 0) {
|
||||
NSLog(@"Syntax error in Autotype Sequence %@ at index: %ld", commands, commandIndex);
|
||||
return nil;
|
||||
}
|
||||
NSString *singleCommand = [currentCommands substringWithRange:NSMakeRange(0, closeBracket.location)];
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
/* 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}
|
||||
+ {+}
|
||||
^ {^}
|
||||
% {%}
|
||||
~ {~}
|
||||
(, ) {(}, {)}
|
||||
[, ] {[}, {]}
|
||||
{, } {{}, {}} {LCURL}, {RCURL}
|
||||
|
||||
*/
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (NSString *)_normalizeCommands:(NSString *)commandString {
|
||||
/* Cache normalized Commands? */
|
||||
NSMutableString *mutableCommand = [commandString mutableCopy];
|
||||
[mutableCommand replaceOccurrencesOfString:kMPAutotypeShortEnter withString:kMPAutotypeEnter options:NSCaseInsensitiveSearch range:NSMakeRange(0, [mutableCommand length])];
|
||||
[mutableCommand replaceOccurrencesOfString:@"{{}" withString:@"{LCURL}" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [mutableCommand length])];
|
||||
[mutableCommand replaceOccurrencesOfString:@"{}}" withString:@"{RCURL}" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [mutableCommand length])];
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#import "MPViewController.h"
|
||||
|
||||
extern NSInteger const kMPDefaultIcon;
|
||||
FOUNDATION_EXTERN NSInteger const kMPDefaultIcon;
|
||||
|
||||
@interface MPIconSelectViewController : MPViewController <NSCollectionViewDelegate>
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
extern uint16_t const kMPUnknownKeyCode;
|
||||
FOUNDATION_EXTERN uint16_t const kMPUnknownKeyCode;
|
||||
|
||||
@interface MPKeyMapper : NSObject
|
||||
|
||||
|
||||
@@ -5,6 +5,19 @@
|
||||
// Created by Michael Starke on 07.02.14.
|
||||
// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
// Uses Code from:
|
||||
// SRKeyCodeTransformer.h
|
||||
// ShortcutRecorder
|
||||
//
|
||||
// Copyright 2006-2007 Contributors. All rights reserved.
|
||||
//
|
||||
// License: BSD
|
||||
//
|
||||
// Contributors:
|
||||
// David Dauer
|
||||
// Jesper
|
||||
// Jamie Kirkpatrick
|
||||
|
||||
|
||||
#import "MPKeyMapper.h"
|
||||
|
||||
@@ -17,20 +30,14 @@ uint16_t const kMPUnknownKeyCode = UINT16_MAX;
|
||||
+ (NSString *)stringForKey:(CGKeyCode)keyCode {
|
||||
TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardInputSource();
|
||||
CFDataRef layoutData = TISGetInputSourceProperty(currentKeyboard,kTISPropertyUnicodeKeyLayoutData);
|
||||
|
||||
if(!layoutData) {
|
||||
currentKeyboard = TISCopyCurrentASCIICapableKeyboardLayoutInputSource();
|
||||
layoutData = (CFDataRef)TISGetInputSourceProperty(currentKeyboard, kTISPropertyUnicodeKeyLayoutData);
|
||||
}
|
||||
CFRelease(currentKeyboard);
|
||||
|
||||
const UCKeyboardLayout *keyboardLayout = (const UCKeyboardLayout *)CFDataGetBytePtr(layoutData);
|
||||
/*
|
||||
Fallback for non-unicode Keyboards taken from to SRKeyCodeTransformer.m
|
||||
Copyright 2006-2007 Contributors. All rights reserved.
|
||||
License: BSD
|
||||
Contributors: David Dauer, Jesper, Jamie Kirkpatrick
|
||||
*/
|
||||
if(!keyboardLayout) {
|
||||
currentKeyboard = TISCopyCurrentASCIICapableKeyboardLayoutInputSource();
|
||||
layoutData = (CFDataRef)TISGetInputSourceProperty(currentKeyboard, kTISPropertyUnicodeKeyLayoutData);
|
||||
CFRelease(currentKeyboard);
|
||||
}
|
||||
|
||||
UInt32 keysDown = 0;
|
||||
UniChar chars[4];
|
||||
|
||||
Reference in New Issue
Block a user