mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 21:13:35 +00:00
Minor progress on parsing commands
This commit is contained in:
@@ -9,16 +9,71 @@
|
|||||||
#import "MPAutotypeCommand.h"
|
#import "MPAutotypeCommand.h"
|
||||||
|
|
||||||
#import "MPAutotypePaste.h"
|
#import "MPAutotypePaste.h"
|
||||||
|
#import "MPAutotypeKeyPress.h"
|
||||||
|
|
||||||
#import "MPAutotypeContext.h"
|
#import "MPAutotypeContext.h"
|
||||||
#import "MPKeyMapper.h"
|
#import "MPKeyMapper.h"
|
||||||
|
|
||||||
|
#import "KPKAutotypeCommands.h"
|
||||||
|
|
||||||
#import "NSString+Commands.h"
|
#import "NSString+Commands.h"
|
||||||
|
|
||||||
#import <Carbon/Carbon.h>
|
#import <Carbon/Carbon.h>
|
||||||
|
|
||||||
@implementation MPAutotypeCommand
|
@implementation MPAutotypeCommand
|
||||||
|
|
||||||
|
+ (NSDictionary *)keypressCommands {
|
||||||
|
static NSDictionary *keypressCommands;
|
||||||
|
static dispatch_once_t onceToken;
|
||||||
|
dispatch_once(&onceToken, ^{
|
||||||
|
keypressCommands = @{ kKPKAutotypeBackspace : @(kVK_Delete),
|
||||||
|
//kKPKAutotypeBreak : @0,
|
||||||
|
kKPKAutotypeCapsLock : @(kVK_CapsLock),
|
||||||
|
kKPKAutotypeDelete : @(kVK_ForwardDelete),
|
||||||
|
kKPKAutotypeDown : @(kVK_DownArrow),
|
||||||
|
kKPKAutotypeEnd : @(kVK_End),
|
||||||
|
kKPKAutotypeEnter : @(kVK_Return),
|
||||||
|
kKPKAutotypeEscape : @(kVK_Escape),
|
||||||
|
kKPKAutotypeHelp : @(kVK_Help),
|
||||||
|
kKPKAutotypeHome : @(kVK_Home),
|
||||||
|
//kKPKAutotypeInsert : @(),
|
||||||
|
kKPKAutotypeLeft : @(kVK_LeftArrow),
|
||||||
|
kKPKAutotypeLeftWindows : @(kVK_Command),
|
||||||
|
//kKPKAutotypeNumlock : @(),
|
||||||
|
kKPKAutotypePageDown : @(kVK_PageDown),
|
||||||
|
kKPKAutotypePageUp : @(kVK_PageUp),
|
||||||
|
//kKPKAutotypePrintScreen : @(),
|
||||||
|
kKPKAutotypeRight : @(kVK_RightArrow),
|
||||||
|
kKPKAutotypeRightWindows : @(kVK_Command),
|
||||||
|
//kKPKAutotypeScrollLock : @(),
|
||||||
|
kKPKAutotypeSpace : @(kVK_Space),
|
||||||
|
kKPKAutotypeTab : @(kVK_Tab),
|
||||||
|
kKPKAutotypeUp : @(kVK_UpArrow),
|
||||||
|
kKPKAutotypeWindows : @(kVK_Command)
|
||||||
|
};
|
||||||
|
});
|
||||||
|
return keypressCommands;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mapping for modifier to CGEventFlags.
|
||||||
|
* @note KeypassControl is mapped to command!
|
||||||
|
*
|
||||||
|
* @return dictionary with commands as keys and CGEventFlags as wrapped values
|
||||||
|
*/
|
||||||
|
+ (NSDictionary *)modifierCommands {
|
||||||
|
static NSDictionary *modifierCommands;
|
||||||
|
static dispatch_once_t onceToken;
|
||||||
|
dispatch_once(&onceToken, ^{
|
||||||
|
modifierCommands = @{
|
||||||
|
kKPKAutotypeAlt : @(kCGEventFlagMaskAlternate),
|
||||||
|
kKPKAutotypeControl : @(kCGEventFlagMaskCommand),
|
||||||
|
kKPKAutotypeShift : @(kCGEventFlagMaskShift)
|
||||||
|
};
|
||||||
|
});
|
||||||
|
return modifierCommands;
|
||||||
|
}
|
||||||
|
|
||||||
+ (NSArray *)commandsForContext:(MPAutotypeContext *)context {
|
+ (NSArray *)commandsForContext:(MPAutotypeContext *)context {
|
||||||
if(![context isValid]) {
|
if(![context isValid]) {
|
||||||
return nil;
|
return nil;
|
||||||
@@ -33,29 +88,37 @@
|
|||||||
[commandRanges addObject:[NSValue valueWithRange:result.range]];
|
[commandRanges addObject:[NSValue valueWithRange:result.range]];
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
NSUInteger skipped = 0;
|
NSUInteger lastLocation = 0;
|
||||||
|
MPAutotypeKeyPress *keyPress;
|
||||||
for(NSValue *rangeValue in commandRanges) {
|
for(NSValue *rangeValue in commandRanges) {
|
||||||
NSRange range = [rangeValue rangeValue];
|
NSRange commandRange = [rangeValue rangeValue];
|
||||||
/* All non-commands will get translated into paste commands */
|
/* All non-commands will get translated into paste commands */
|
||||||
if(range.location > skipped) {
|
if(commandRange.location > lastLocation) {
|
||||||
NSString *pasteValue = [context.normalizedCommand substringWithRange:NSMakeRange(skipped, range.location - skipped)];
|
/* If were modifiers we need to use the next single stroke and make update the modifier command */
|
||||||
|
if(keyPress) {
|
||||||
|
}
|
||||||
|
NSString *pasteValue = [context.normalizedCommand substringWithRange:NSMakeRange(lastLocation, commandRange.location - lastLocation)];
|
||||||
|
// Determin if it's amodifier key, and collect them!
|
||||||
[self appendPasteCommandForContent:pasteValue toCommands:commands];
|
[self appendPasteCommandForContent:pasteValue toCommands:commands];
|
||||||
skipped = range.location;
|
|
||||||
}
|
}
|
||||||
|
NSString *commandString = [context.normalizedCommand substringWithRange:commandRange];
|
||||||
|
[self appendCommandForString:commandString toCommands:commands];
|
||||||
|
lastLocation = commandRange.location;
|
||||||
}
|
}
|
||||||
return nil;
|
return commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (MPAutotypeCommand *)appendPasteCommandForContent:(NSString *)pasteContent toCommands:(NSMutableArray *)commands {
|
+ (void)appendPasteCommandForContent:(NSString *)pasteContent toCommands:(NSMutableArray *)commands {
|
||||||
if(pasteContent) {
|
if(pasteContent) {
|
||||||
MPAutotypePaste *pasteCommand = [[MPAutotypePaste alloc] initWithString:pasteContent];
|
MPAutotypePaste *pasteCommand = [[MPAutotypePaste alloc] initWithString:pasteContent];
|
||||||
[commands addObject:pasteCommand];
|
[commands addObject:pasteCommand];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (MPAutotypeCommand *)appendCommandForString:(NSString *)commandString toCommands:(NSMutableArray *)commands {
|
+ (void)appendCommandForString:(NSString *)commandString toCommands:(NSMutableArray *)commands {
|
||||||
if(commandString) {
|
MPAutotypeCommand *
|
||||||
/* Find appropriate command */
|
if(!commandString) {
|
||||||
|
NSDictionary *modifier = [self modifierCommands];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user