mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-13 22:52:26 +00:00
progress on searching auto type candidates
This commit is contained in:
Submodule KeePassKit updated: d46ebc801c...6992db3611
@@ -240,6 +240,8 @@
|
||||
4CD884B715BD47080042BBF8 /* DocumentWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4CD884B615BD47080042BBF8 /* DocumentWindow.xib */; };
|
||||
4CDB5C421794AA4F0017667E /* KPKTree+Serializing.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CDB5C411794AA4F0017667E /* KPKTree+Serializing.m */; };
|
||||
4CDF01A316D1B76700D0AC08 /* MPEntryViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CDF01A216D1B76700D0AC08 /* MPEntryViewController.m */; };
|
||||
4CE2961518429AA5005F01CE /* MPAutotypeKeyPress.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE2961418429AA5005F01CE /* MPAutotypeKeyPress.m */; };
|
||||
4CE296191842A166005F01CE /* MPAutotypePaste.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE296181842A166005F01CE /* MPAutotypePaste.m */; };
|
||||
4CE298EB1795FC2A00DF7BDB /* MPEntryContextMenuDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE298EA1795FC2A00DF7BDB /* MPEntryContextMenuDelegate.m */; };
|
||||
4CE39ABF16ECE34A000FE29D /* MPIconSelectViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE39ABE16ECE34A000FE29D /* MPIconSelectViewController.m */; };
|
||||
4CE39AC116ECE359000FE29D /* IconSelection.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4CE39AC016ECE359000FE29D /* IconSelection.xib */; };
|
||||
@@ -705,6 +707,10 @@
|
||||
4CDB5C411794AA4F0017667E /* KPKTree+Serializing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = "KPKTree+Serializing.m"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
|
||||
4CDF01A116D1B76700D0AC08 /* MPEntryViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPEntryViewController.h; sourceTree = "<group>"; };
|
||||
4CDF01A216D1B76700D0AC08 /* MPEntryViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPEntryViewController.m; sourceTree = "<group>"; };
|
||||
4CE2961318429AA5005F01CE /* MPAutotypeKeyPress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPAutotypeKeyPress.h; sourceTree = "<group>"; };
|
||||
4CE2961418429AA5005F01CE /* MPAutotypeKeyPress.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPAutotypeKeyPress.m; sourceTree = "<group>"; };
|
||||
4CE296171842A166005F01CE /* MPAutotypePaste.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPAutotypePaste.h; sourceTree = "<group>"; };
|
||||
4CE296181842A166005F01CE /* MPAutotypePaste.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPAutotypePaste.m; sourceTree = "<group>"; };
|
||||
4CE298E91795FC2A00DF7BDB /* MPEntryContextMenuDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPEntryContextMenuDelegate.h; sourceTree = "<group>"; };
|
||||
4CE298EA1795FC2A00DF7BDB /* MPEntryContextMenuDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPEntryContextMenuDelegate.m; sourceTree = "<group>"; };
|
||||
4CE39ABD16ECE34A000FE29D /* MPIconSelectViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPIconSelectViewController.h; sourceTree = "<group>"; };
|
||||
@@ -1305,8 +1311,12 @@
|
||||
children = (
|
||||
4CEE46DB181C301D006BF1E5 /* MPAutotypeDaemon.h */,
|
||||
4CEE46DC181C301D006BF1E5 /* MPAutotypeDaemon.m */,
|
||||
4CE2961318429AA5005F01CE /* MPAutotypeKeyPress.h */,
|
||||
4CE2961418429AA5005F01CE /* MPAutotypeKeyPress.m */,
|
||||
4C89F522182FB4740069C73C /* MPAutotypeCommand.h */,
|
||||
4C89F523182FB4740069C73C /* MPAutotypeCommand.m */,
|
||||
4CE296171842A166005F01CE /* MPAutotypePaste.h */,
|
||||
4CE296181842A166005F01CE /* MPAutotypePaste.m */,
|
||||
);
|
||||
name = Autotype;
|
||||
sourceTree = "<group>";
|
||||
@@ -1913,6 +1923,7 @@
|
||||
4CAF62FC1763604000CD7084 /* HNHBadgedTextFieldCell.m in Sources */,
|
||||
4C58BD4F176370B100B8178C /* HNHBadgedTextField.m in Sources */,
|
||||
4C01C2421764D8980016D5D0 /* MPContextMenuHelper.m in Sources */,
|
||||
4CE296191842A166005F01CE /* MPAutotypePaste.m in Sources */,
|
||||
4C01C245176500C40016D5D0 /* HNHLevelIndicatorCell.m in Sources */,
|
||||
4C569D9E17652B0600595B62 /* MPConstants.m in Sources */,
|
||||
4C569DA117652BFE00595B62 /* MPEntryTableDataSource.m in Sources */,
|
||||
@@ -2026,6 +2037,7 @@
|
||||
4C68456D17BC227B00FCDBFC /* KPKWindowAssociation.m in Sources */,
|
||||
4CA2E2DB17BCDA8300714076 /* NSString+Placeholder.m in Sources */,
|
||||
4C6C72C417C01E4200768849 /* NSMutableData+KeePassKit.m in Sources */,
|
||||
4CE2961518429AA5005F01CE /* MPAutotypeKeyPress.m in Sources */,
|
||||
4C0104BB17C37BFC00173EF3 /* KPKLegacyHeaderUtility.m in Sources */,
|
||||
4C0104BE17C37DA400173EF3 /* KPKXmlUtilities.m in Sources */,
|
||||
4C5CD35517D15DBD000B7F38 /* NSData+Gzip.m in Sources */,
|
||||
|
||||
@@ -8,10 +8,38 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
/**
|
||||
* The Autotype command reperesent a capsualted Action that was determined by interpreting
|
||||
* Autotype field for a given entry. This is a class cluster and schould be considered the sole
|
||||
* enty point for creating AutotypeCommands.
|
||||
*/
|
||||
@interface MPAutotypeCommand : NSObject
|
||||
|
||||
@property (copy) NSString *commandString;
|
||||
@property (readonly, copy) NSString *commandString;
|
||||
|
||||
+ (NSArray *)commandsForCommandString:(NSString *)commands;
|
||||
/**
|
||||
* Determines the Keycode for the given keyboard layout for the supplied character
|
||||
*
|
||||
* @param uchrHeader The KeyboardLayout
|
||||
* @param character The Character that needs to be pressed
|
||||
*
|
||||
* @return Key code in the supplied keyboard layout
|
||||
*/
|
||||
- (CGKeyCode)keyCodeForKeyboard:(const UCKeyboardLayout *)uchrHeader character:(NSString *)character;
|
||||
/**
|
||||
* Sends a KeyPress Event with the supplied modifier flags and Keycode
|
||||
* Any existing modifiers will be disabled for this event. If the user
|
||||
* presses any key, those will be ignored during this event
|
||||
*
|
||||
* @param keyCode virtual KeyCode to be sent
|
||||
* @param flags modifier flags for the key press event
|
||||
*/
|
||||
- (void)sendPressKey:(CGKeyCode)keyCode modifierFlags:(CGEventFlags)flags;
|
||||
|
||||
/**
|
||||
* Exectues the Autotype Command. This will be called by the autotype daemon.
|
||||
*/
|
||||
- (void)execute;
|
||||
|
||||
@end
|
||||
|
||||
@@ -7,11 +7,191 @@
|
||||
//
|
||||
|
||||
#import "MPAutotypeCommand.h"
|
||||
#import "NSString+Commands.h"
|
||||
|
||||
#import <Carbon/Carbon.h>
|
||||
|
||||
/*
|
||||
|
||||
Autotype workflow:
|
||||
|
||||
run copy/paste with content
|
||||
|
||||
special 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}
|
||||
Shift +
|
||||
Ctrl ^
|
||||
Alt %
|
||||
+ {+}
|
||||
^ {^}
|
||||
% {%}
|
||||
~ {~}
|
||||
(, ) {(}, {)}
|
||||
[, ] {[}, {]}
|
||||
{, } {{}, {}}
|
||||
|
||||
special commands:
|
||||
|
||||
{DELAY X} Delays X milliseconds.
|
||||
{CLEARFIELD} Clears the contents of the edit control that currently has the focus (only single-line edit controls).
|
||||
{VKEY X}
|
||||
*/
|
||||
|
||||
@implementation MPAutotypeCommand
|
||||
|
||||
- (void)execute {
|
||||
// todo;
|
||||
+ (NSArray *)commandsForCommandString:(NSString *)commands {
|
||||
NSUInteger commandIndex = 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 */
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)sendPressKey:(CGKeyCode)keyCode modifierFlags:(CGEventFlags)flags {
|
||||
CGEventRef pressKey = CGEventCreateKeyboardEvent (NULL, keyCode, YES);
|
||||
CGEventRef releaseKey = CGEventCreateKeyboardEvent (NULL, keyCode, NO);
|
||||
|
||||
CGEventSetFlags(pressKey,0);
|
||||
CGEventSetFlags(releaseKey, 0);
|
||||
CGEventSetFlags(pressKey,flags);
|
||||
CGEventSetFlags(releaseKey, flags);
|
||||
|
||||
CGEventPost(kCGSessionEventTap, pressKey);
|
||||
CGEventPost(kCGSessionEventTap, releaseKey);
|
||||
|
||||
CFRelease(pressKey);
|
||||
CFRelease(releaseKey);
|
||||
}
|
||||
|
||||
/*
|
||||
cody by Joe Turner http://www.cocoabuilder.com/archive/cocoa/242992-detect-keyboard-layout-for-cgkeycodes.html#243168
|
||||
*/
|
||||
- (CGKeyCode)keyCodeForKeyboard:(const UCKeyboardLayout *)uchrHeader character:(NSString *)character {
|
||||
if ([character isEqualToString:@"RETURN"]) return kVK_Return;
|
||||
if ([character isEqualToString:@"TAB"]) return kVK_Tab;
|
||||
if ([character isEqualToString:@"SPACE"]) return kVK_Space;
|
||||
if ([character isEqualToString:@"DELETE"]) return kVK_Delete;
|
||||
if ([character isEqualToString:@"ESCAPE"]) return kVK_Escape;
|
||||
if ([character isEqualToString:@"F5"]) return kVK_F5;
|
||||
if ([character isEqualToString:@"F6"]) return kVK_F6;
|
||||
if ([character isEqualToString:@"F7"]) return kVK_F7;
|
||||
if ([character isEqualToString:@"F3"]) return kVK_F3;
|
||||
if ([character isEqualToString:@"F8"]) return kVK_F8;
|
||||
if ([character isEqualToString:@"F9"]) return kVK_F9;
|
||||
if ([character isEqualToString:@"F11"]) return kVK_F11;
|
||||
if ([character isEqualToString:@"F13"]) return kVK_F13;
|
||||
if ([character isEqualToString:@"F16"]) return kVK_F16;
|
||||
if ([character isEqualToString:@"F14"]) return kVK_F14;
|
||||
if ([character isEqualToString:@"F10"]) return kVK_F10;
|
||||
if ([character isEqualToString:@"F12"]) return kVK_F12;
|
||||
if ([character isEqualToString:@"F15"]) return kVK_F15;
|
||||
if ([character isEqualToString:@"HELP"]) return kVK_Help;
|
||||
if ([character isEqualToString:@"HOME"]) return kVK_Home;
|
||||
if ([character isEqualToString:@"PAGE UP"]) return kVK_PageUp;
|
||||
if ([character isEqualToString:@"FORWARD DELETE"]) return kVK_ForwardDelete;
|
||||
if ([character isEqualToString:@"F4"]) return kVK_F4;
|
||||
if ([character isEqualToString:@"END"]) return kVK_End;
|
||||
if ([character isEqualToString:@"F2"]) return kVK_F2;
|
||||
if ([character isEqualToString:@"PAGE DOWN"]) return kVK_PageDown;
|
||||
if ([character isEqualToString:@"F1"]) return kVK_F1;
|
||||
if ([character isEqualToString:@"LEFT"]) return kVK_LeftArrow;
|
||||
if ([character isEqualToString:@"RIGHT"]) return kVK_RightArrow;
|
||||
if ([character isEqualToString:@"DOWN"]) return kVK_DownArrow;
|
||||
if ([character isEqualToString:@"UP"]) return kVK_UpArrow;
|
||||
|
||||
UTF16Char theCharacter = [character characterAtIndex:0];
|
||||
long i, j, k;
|
||||
unsigned char *uchrData = (unsigned char *)uchrHeader;
|
||||
UCKeyboardTypeHeader *uchrTable = uchrHeader->keyboardTypeList;
|
||||
BOOL found = NO;
|
||||
UInt16 virtualKeyCode;
|
||||
|
||||
for (i = 0; i < (uchrHeader->keyboardTypeCount) && !found; i++) {
|
||||
UCKeyToCharTableIndex *uchrKeyIX;
|
||||
UCKeyStateRecordsIndex *stateRecordsIndex;
|
||||
|
||||
if (uchrTable[i].keyStateRecordsIndexOffset != 0 ) {
|
||||
stateRecordsIndex = (UCKeyStateRecordsIndex *) (((unsigned char*)uchrData) + (uchrTable[i].keyStateRecordsIndexOffset));
|
||||
|
||||
if ((stateRecordsIndex->keyStateRecordsIndexFormat) != kUCKeyStateRecordsIndexFormat) {
|
||||
stateRecordsIndex = NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
stateRecordsIndex = NULL;
|
||||
}
|
||||
|
||||
uchrKeyIX = (UCKeyToCharTableIndex *)(((unsigned char *)uchrData) + (uchrTable[i].keyToCharTableIndexOffset));
|
||||
|
||||
if (kUCKeyToCharTableIndexFormat == (uchrKeyIX-> keyToCharTableIndexFormat)) {
|
||||
for (j = 0; j < (uchrKeyIX->keyToCharTableCount) && !found; j++) {
|
||||
UCKeyOutput *keyToCharData = (UCKeyOutput *) ( ((unsigned char*)uchrData) + (uchrKeyIX->keyToCharTableOffsets[j]) );
|
||||
|
||||
for (k = 0; k < (uchrKeyIX->keyToCharTableSize) && !found; k++) {
|
||||
if (((keyToCharData[k]) & kUCKeyOutputTestForIndexMask) == kUCKeyOutputStateIndexMask) {
|
||||
long theIndex = (kUCKeyOutputGetIndexMask & keyToCharData[k]);
|
||||
|
||||
if (stateRecordsIndex != NULL && theIndex <= stateRecordsIndex-> keyStateRecordCount) {
|
||||
UCKeyStateRecord *theStateRecord = (UCKeyStateRecord *) (((unsigned char *) uchrData) + (stateRecordsIndex-> keyStateRecordOffsets[theIndex]));
|
||||
|
||||
if ((theStateRecord->stateZeroCharData) == theCharacter) {
|
||||
virtualKeyCode = k;
|
||||
found = YES;
|
||||
}
|
||||
} else {
|
||||
if ((keyToCharData[k]) == theCharacter) {
|
||||
virtualKeyCode = k;
|
||||
found = YES;
|
||||
}
|
||||
}
|
||||
} else if (((keyToCharData[k]) & kUCKeyOutputTestForIndexMask) == kUCKeyOutputSequenceIndexMask) {
|
||||
} else if ( (keyToCharData[k]) == 0xFFFE || (keyToCharData[k]) == 0xFFFF ) {
|
||||
} else {
|
||||
if ((keyToCharData[k]) == theCharacter) {
|
||||
virtualKeyCode = k;
|
||||
found = YES;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return (CGKeyCode)virtualKeyCode;
|
||||
}
|
||||
|
||||
- (void)execute {}
|
||||
|
||||
@end
|
||||
|
||||
@@ -8,9 +8,13 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class KPKEntry;
|
||||
|
||||
/**
|
||||
* The autotype daemon is repsonsible for registering the globa hotkey and to perform any autotype actions
|
||||
*/
|
||||
@interface MPAutotypeDaemon : NSObject
|
||||
|
||||
- (void)exectureAutotypeForEntry:(KPKEntry *)entry withWindowTitle:(NSString *)title;
|
||||
|
||||
@end
|
||||
|
||||
@@ -16,61 +16,6 @@
|
||||
|
||||
#import <Carbon/Carbon.h>
|
||||
|
||||
/*
|
||||
|
||||
Autotype workflow:
|
||||
|
||||
run copy/paste with content
|
||||
|
||||
special 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}
|
||||
Shift +
|
||||
Ctrl ^
|
||||
Alt %
|
||||
+ {+}
|
||||
^ {^}
|
||||
% {%}
|
||||
~ {~}
|
||||
(, ) {(}, {)}
|
||||
[, ] {[}, {]}
|
||||
{, } {{}, {}}
|
||||
|
||||
special commands:
|
||||
|
||||
{DELAY X} Delays X milliseconds.
|
||||
{CLEARFIELD} Clears the contents of the edit control that currently has the focus (only single-line edit controls).
|
||||
{VKEY X}
|
||||
*/
|
||||
|
||||
@implementation MPAutotypeDaemon
|
||||
|
||||
- (id)init {
|
||||
@@ -109,10 +54,17 @@
|
||||
We do not care where this came form, just get the autotype commands
|
||||
*/
|
||||
NSArray *autotypeCandidates = [[currentDocument findEntriesForWindowTitle:windowTitle] lastObject];
|
||||
if([autotypeCandidates count] == 0) {
|
||||
NSUInteger candiates = [autotypeCandidates count];
|
||||
if(candiates == 0) {
|
||||
return; // No Entries found.
|
||||
}
|
||||
|
||||
|
||||
if(candiates > 1) {
|
||||
// open Dialog to select from possible entries
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
Implement!
|
||||
*/
|
||||
@@ -129,17 +81,6 @@
|
||||
Translate to paste/copy commands
|
||||
Find correct key-codes for current keyboard layout to perform paste command
|
||||
*/
|
||||
MPPasteBoardController *controller = [MPPasteBoardController defaultController];
|
||||
if(selectedEntry.username) {
|
||||
[controller copyObjects:@[selectedEntry.username]];
|
||||
[self _pressKey:kVK_ANSI_V modifierFlags:kCGEventFlagMaskCommand];
|
||||
}
|
||||
if(selectedEntry.password) {
|
||||
[self _pressKey:kVK_Tab modifierFlags:0];
|
||||
[controller copyObjects:@[selectedEntry.password]];
|
||||
[self _pressKey:kVK_ANSI_V modifierFlags:kCGEventFlagMaskCommand];
|
||||
}
|
||||
[self _pressKey:kVK_Return modifierFlags:0];
|
||||
}
|
||||
|
||||
- (void)_registerHotKey {
|
||||
@@ -150,22 +91,6 @@
|
||||
object:nil];
|
||||
}
|
||||
|
||||
- (void)_pressKey:(CGKeyCode)keyCode modifierFlags:(CGEventFlags)flags {
|
||||
CGEventRef pressKey = CGEventCreateKeyboardEvent (NULL, keyCode, YES);
|
||||
CGEventRef releaseKey = CGEventCreateKeyboardEvent (NULL, keyCode, NO);
|
||||
|
||||
CGEventSetFlags(pressKey,0);
|
||||
CGEventSetFlags(releaseKey, 0);
|
||||
CGEventSetFlags(pressKey,flags);
|
||||
CGEventSetFlags(releaseKey, flags);
|
||||
|
||||
CGEventPost(kCGSessionEventTap, pressKey);
|
||||
CGEventPost(kCGSessionEventTap, releaseKey);
|
||||
|
||||
CFRelease(pressKey);
|
||||
CFRelease(releaseKey);
|
||||
}
|
||||
|
||||
- (NSString *)_frontMostWindowTitle {
|
||||
NSRunningApplication *frontApplication = [[NSWorkspace sharedWorkspace] frontmostApplication];
|
||||
|
||||
@@ -179,101 +104,4 @@
|
||||
return nil;
|
||||
}
|
||||
|
||||
/*
|
||||
cody by Joe Turner http://www.cocoabuilder.com/archive/cocoa/242992-detect-keyboard-layout-for-cgkeycodes.html#243168
|
||||
*/
|
||||
- (CGKeyCode)keyCodeForKeyboard:(const UCKeyboardLayout *)uchrHeader character:(NSString *)character {
|
||||
if ([character isEqualToString:@"RETURN"]) return kVK_Return;
|
||||
if ([character isEqualToString:@"TAB"]) return kVK_Tab;
|
||||
if ([character isEqualToString:@"SPACE"]) return kVK_Space;
|
||||
if ([character isEqualToString:@"DELETE"]) return kVK_Delete;
|
||||
if ([character isEqualToString:@"ESCAPE"]) return kVK_Escape;
|
||||
if ([character isEqualToString:@"F5"]) return kVK_F5;
|
||||
if ([character isEqualToString:@"F6"]) return kVK_F6;
|
||||
if ([character isEqualToString:@"F7"]) return kVK_F7;
|
||||
if ([character isEqualToString:@"F3"]) return kVK_F3;
|
||||
if ([character isEqualToString:@"F8"]) return kVK_F8;
|
||||
if ([character isEqualToString:@"F9"]) return kVK_F9;
|
||||
if ([character isEqualToString:@"F11"]) return kVK_F11;
|
||||
if ([character isEqualToString:@"F13"]) return kVK_F13;
|
||||
if ([character isEqualToString:@"F16"]) return kVK_F16;
|
||||
if ([character isEqualToString:@"F14"]) return kVK_F14;
|
||||
if ([character isEqualToString:@"F10"]) return kVK_F10;
|
||||
if ([character isEqualToString:@"F12"]) return kVK_F12;
|
||||
if ([character isEqualToString:@"F15"]) return kVK_F15;
|
||||
if ([character isEqualToString:@"HELP"]) return kVK_Help;
|
||||
if ([character isEqualToString:@"HOME"]) return kVK_Home;
|
||||
if ([character isEqualToString:@"PAGE UP"]) return kVK_PageUp;
|
||||
if ([character isEqualToString:@"FORWARD DELETE"]) return kVK_ForwardDelete;
|
||||
if ([character isEqualToString:@"F4"]) return kVK_F4;
|
||||
if ([character isEqualToString:@"END"]) return kVK_End;
|
||||
if ([character isEqualToString:@"F2"]) return kVK_F2;
|
||||
if ([character isEqualToString:@"PAGE DOWN"]) return kVK_PageDown;
|
||||
if ([character isEqualToString:@"F1"]) return kVK_F1;
|
||||
if ([character isEqualToString:@"LEFT"]) return kVK_LeftArrow;
|
||||
if ([character isEqualToString:@"RIGHT"]) return kVK_RightArrow;
|
||||
if ([character isEqualToString:@"DOWN"]) return kVK_DownArrow;
|
||||
if ([character isEqualToString:@"UP"]) return kVK_UpArrow;
|
||||
|
||||
UTF16Char theCharacter = [character characterAtIndex:0];
|
||||
long i, j, k;
|
||||
unsigned char *uchrData = (unsigned char *)uchrHeader;
|
||||
UCKeyboardTypeHeader *uchrTable = uchrHeader->keyboardTypeList;
|
||||
BOOL found = NO;
|
||||
UInt16 virtualKeyCode;
|
||||
|
||||
for (i = 0; i < (uchrHeader->keyboardTypeCount) && !found; i++) {
|
||||
UCKeyToCharTableIndex *uchrKeyIX;
|
||||
UCKeyStateRecordsIndex *stateRecordsIndex;
|
||||
|
||||
if (uchrTable[i].keyStateRecordsIndexOffset != 0 ) {
|
||||
stateRecordsIndex = (UCKeyStateRecordsIndex *) (((unsigned char*)uchrData) + (uchrTable[i].keyStateRecordsIndexOffset));
|
||||
|
||||
if ((stateRecordsIndex->keyStateRecordsIndexFormat) != kUCKeyStateRecordsIndexFormat) {
|
||||
stateRecordsIndex = NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
stateRecordsIndex = NULL;
|
||||
}
|
||||
|
||||
uchrKeyIX = (UCKeyToCharTableIndex *)(((unsigned char *)uchrData) + (uchrTable[i].keyToCharTableIndexOffset));
|
||||
|
||||
if (kUCKeyToCharTableIndexFormat == (uchrKeyIX-> keyToCharTableIndexFormat)) {
|
||||
for (j = 0; j < (uchrKeyIX->keyToCharTableCount) && !found; j++) {
|
||||
UCKeyOutput *keyToCharData = (UCKeyOutput *) ( ((unsigned char*)uchrData) + (uchrKeyIX->keyToCharTableOffsets[j]) );
|
||||
|
||||
for (k = 0; k < (uchrKeyIX->keyToCharTableSize) && !found; k++) {
|
||||
if (((keyToCharData[k]) & kUCKeyOutputTestForIndexMask) == kUCKeyOutputStateIndexMask) {
|
||||
long theIndex = (kUCKeyOutputGetIndexMask & keyToCharData[k]);
|
||||
|
||||
if (stateRecordsIndex != NULL && theIndex <= stateRecordsIndex-> keyStateRecordCount) {
|
||||
UCKeyStateRecord *theStateRecord = (UCKeyStateRecord *) (((unsigned char *) uchrData) + (stateRecordsIndex-> keyStateRecordOffsets[theIndex]));
|
||||
|
||||
if ((theStateRecord->stateZeroCharData) == theCharacter) {
|
||||
virtualKeyCode = k;
|
||||
found = YES;
|
||||
}
|
||||
} else {
|
||||
if ((keyToCharData[k]) == theCharacter) {
|
||||
virtualKeyCode = k;
|
||||
found = YES;
|
||||
}
|
||||
}
|
||||
} else if (((keyToCharData[k]) & kUCKeyOutputTestForIndexMask) == kUCKeyOutputSequenceIndexMask) {
|
||||
} else if ( (keyToCharData[k]) == 0xFFFE || (keyToCharData[k]) == 0xFFFF ) {
|
||||
} else {
|
||||
if ((keyToCharData[k]) == theCharacter) {
|
||||
virtualKeyCode = k;
|
||||
found = YES;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return (CGKeyCode)virtualKeyCode;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
14
MacPass/MPAutotypeKeyPress.h
Normal file
14
MacPass/MPAutotypeKeyPress.h
Normal file
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// MPAutotypeSpecialKey.h
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 24/11/13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPAutotypeCommand.h"
|
||||
|
||||
|
||||
@interface MPAutotypeKeyPress : MPAutotypeCommand
|
||||
|
||||
@end
|
||||
17
MacPass/MPAutotypeKeyPress.m
Normal file
17
MacPass/MPAutotypeKeyPress.m
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// MPAutotypeSpecialKey.m
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 24/11/13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPAutotypeKeyPress.h"
|
||||
|
||||
@implementation MPAutotypeKeyPress
|
||||
|
||||
- (void)execute {
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
13
MacPass/MPAutotypePaste.h
Normal file
13
MacPass/MPAutotypePaste.h
Normal file
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// MPAutotypePaste.h
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 24/11/13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPAutotypeCommand.h"
|
||||
|
||||
@interface MPAutotypePaste : MPAutotypeCommand
|
||||
|
||||
@end
|
||||
27
MacPass/MPAutotypePaste.m
Normal file
27
MacPass/MPAutotypePaste.m
Normal file
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// MPAutotypePaste.m
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 24/11/13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPAutotypePaste.h"
|
||||
#import "MPPasteBoardController.h"
|
||||
|
||||
#import <Carbon/Carbon.h>
|
||||
|
||||
@implementation MPAutotypePaste
|
||||
|
||||
/**
|
||||
* Simple copy paste action
|
||||
*/
|
||||
- (void)execute {
|
||||
if([self.commandString length] > 0) {
|
||||
MPPasteBoardController *controller = [MPPasteBoardController defaultController];
|
||||
[controller copyObjects:@[self.commandString]];
|
||||
[self sendPressKey:kVK_ANSI_V modifierFlags:kCGEventFlagMaskCommand];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -15,10 +15,17 @@
|
||||
@implementation MPDocument (Autotype)
|
||||
|
||||
- (NSArray *)findEntriesForWindowTitle:(NSString *)windowTitle {
|
||||
|
||||
NSArray *autotypeEntries = [self.root autotypeableChildEntries];
|
||||
NSMutableArray *matchingEntries = [[NSMutableArray alloc] initWithCapacity:ceil([autotypeEntries count] / 4.0)];
|
||||
for(KPKEntry *entry in autotypeEntries) {
|
||||
//KPKAutotype *autotype = entry.autotype;
|
||||
/* Test for title */
|
||||
NSRange titleRange = [entry.title rangeOfString:windowTitle options:NSCaseInsensitiveSearch];
|
||||
if(titleRange.location != NSNotFound) {
|
||||
[matchingEntries addObject:entry];
|
||||
}
|
||||
/* search in Autotype entries for match */
|
||||
else {
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user