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

@@ -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;
}