Added better support for special caracters in Autotype sequecne (+, ~, ^ and %)

This commit is contained in:
michael starke
2016-06-30 12:33:45 +02:00
parent 7a09cb9588
commit f372ca772c
6 changed files with 43 additions and 174 deletions

View File

@@ -1,14 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9532"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="MPInspectorViewController">
<connections>
<outlet property="bottomBar" destination="2930" id="2995"/>
<outlet property="cancelEditButton" destination="3126" id="3141"/>
<outlet property="editButton" destination="3109" id="3122"/>
<outlet property="itemImageView" destination="2998" id="3024"/>
<outlet property="itemNameTextField" destination="3013" id="3025"/>
@@ -34,33 +33,11 @@
<font key="font" metaFont="system"/>
</buttonCell>
</button>
<button verticalHuggingPriority="750" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="3126">
<rect key="frame" x="154" y="2" width="57" height="25"/>
<buttonCell key="cell" type="roundTextured" title="Cancel" bezelStyle="texturedRounded" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="3127">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="cancelChangesToSelectedItem:" target="-1" id="Hg9-6o-dRD"/>
</connections>
</button>
<button hidden="YES" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="jBD-3D-knW">
<rect key="frame" x="20" y="2" width="59" height="25"/>
<buttonCell key="cell" type="roundTextured" title="History" bezelStyle="texturedRounded" alignment="center" enabled="NO" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="w1z-1n-b0m">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="showHistory:" target="-1" id="Ay6-cl-onN"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstAttribute="height" constant="30" id="2949"/>
<constraint firstItem="3126" firstAttribute="baseline" secondItem="3109" secondAttribute="baseline" id="3129"/>
<constraint firstAttribute="trailing" secondItem="3109" secondAttribute="trailing" constant="20" symbolic="YES" id="3138"/>
<constraint firstItem="3109" firstAttribute="centerY" secondItem="2930" secondAttribute="centerY" id="3139"/>
<constraint firstItem="3109" firstAttribute="leading" secondItem="3126" secondAttribute="trailing" constant="8" symbolic="YES" id="3140"/>
</constraints>
</customView>
<imageView translatesAutoresizingMaskIntoConstraints="NO" id="2998" customClass="MPPopupImageView">

View File

@@ -75,6 +75,26 @@ static CGKeyCode kMPFunctionKeyCodes[] = { kVK_F1, kVK_F2, kVK_F3, kVK_F4, kVK_F
});
return keypressCommands;
}
/* Commands that are actually just one symbol to be pasted */
+ (NSDictionary *)pasteableCommands {
static NSDictionary *pasteableCommands;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
pasteableCommands = @{
kKPKAutotypePlus: @"+",
kKPKAutotypeOr: @"^",
kKPKAutotypePercent: @"%",
kKPKAutotypeTilde : @"~",
kKPKAutotypeRoundBracketLeft : @"(",
kKPKAutotypeRoundBracketRight : @")",
kKPKAutotypeSquareBracketLeft : @"[",
kKPKAutotypeSquareBracketRight : @"]",
kKPKAutotypeCurlyBracketLeft: @"{",
kKPKAutotypeCurlyBracketRight: @"}"
};
});
return pasteableCommands;
}
/**
* Mapping for modifier to CGEventFlags.
@@ -112,7 +132,7 @@ static CGKeyCode kMPFunctionKeyCodes[] = { kVK_F1, kVK_F2, kVK_F3, kVK_F4, kVK_F
NSUInteger lastLocation = 0;
CGEventFlags collectedModifers = 0;
for(NSValue *rangeValue in commandRanges) {
NSRange commandRange = [rangeValue rangeValue];
NSRange commandRange = rangeValue.rangeValue;
/* All non-commands will get translated into paste commands */
if(commandRange.location > lastLocation) {
/* If there were modifiers we need to use the next single stroke and update the modifier command */
@@ -268,6 +288,13 @@ static CGKeyCode kMPFunctionKeyCodes[] = { kVK_F1, kVK_F2, kVK_F3, kVK_F4, kVK_F
[commands addObject:[[MPAutotypeKeyPress alloc] initWithModifierMask:flags keyCode:keyCode]];
return; // Done
}
/* {PLUS}, {TILDE}, {PERCENT}, {+}, etc */
NSString *pasteConent = [self pasteableCommands][uppercaseCommand];
if(pasteConent) {
[self appendAppropriatePasteCommandForEntry:entry withContent:pasteConent toCommands:commands];
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)];
@@ -321,6 +348,7 @@ static CGKeyCode kMPFunctionKeyCodes[] = { kVK_F1, kVK_F2, kVK_F3, kVK_F4, kVK_F
}
}
else {
/* Fallback */
[self appendAppropriatePasteCommandForEntry:entry withContent:commandString toCommands:commands];
}
}

View File

@@ -64,30 +64,31 @@ uint16_t const kMPUnknownKeyCode = UINT16_MAX;
NSString *localizedName = (__bridge NSString *)TISGetInputSourceProperty(currentKeyboard, kTISPropertyLocalizedName);
CFRelease(currentKeyboard);
/* Initalize the keyboardCodeDictonary */
if(keyboardCodeDictionary == nil) {
/* Input source should not change that much while we are running */
keyboardCodeDictionary = [[NSMutableDictionary alloc] initWithCapacity:2];
}
NSDictionary *charToCodeDict = keyboardCodeDictionary[localizedName];
if(nil == keyboardCodeDictionary[localizedName]) {
/* We need 128 places for this dict */
charToCodeDict = [[NSMutableDictionary alloc] initWithCapacity:128];
/* search for current character mapping */
NSDictionary<NSString *, NSNumber *> *charToCodeDict = keyboardCodeDictionary[localizedName];
if(nil == charToCodeDict) {
/* Add mapping */
NSMutableDictionary *tempCharToCodeDict = [[NSMutableDictionary alloc] initWithCapacity:128];
/* Generate table of keycodes and characters. */
/* Loop through every keycode (0 - 127) to find its current mapping. */
for(CGKeyCode keyCode = 0; keyCode < 128; ++keyCode) {
NSString *string = [self stringForKey:keyCode];
if(string != nil) {
((NSMutableDictionary *)charToCodeDict)[string] = @(keyCode);
tempCharToCodeDict[string] = @(keyCode);
}
}
keyboardCodeDictionary[localizedName] = [[NSDictionary alloc] initWithDictionary:charToCodeDict];
keyboardCodeDictionary[localizedName] = [[NSDictionary alloc] initWithDictionary:tempCharToCodeDict];
}
/* Add mapping */
/* Generate table of keycodes and characters. */
NSString *singleCharacter = [[character substringToIndex:1] lowercaseString];
NSString *singleCharacter = [character substringToIndex:1].lowercaseString;
if(charToCodeDict[singleCharacter]) {
return [charToCodeDict[singleCharacter] integerValue];
return charToCodeDict[singleCharacter].integerValue;
}
return kMPUnknownKeyCode;
}