Only in /Users/chris/Downloads/HotKeysLib3/PTHotKeysLib/src: .DS_Store Only in src: .svn diff -u /Users/chris/Downloads/HotKeysLib3/PTHotKeysLib/src/PTHotKeyCenter.m src/PTHotKeyCenter.m --- /Users/chris/Downloads/HotKeysLib3/PTHotKeysLib/src/PTHotKeyCenter.m 2005-11-28 01:25:06.000000000 -0500 +++ src/PTHotKeyCenter.m 2008-05-04 20:46:12.000000000 -0400 @@ -84,7 +84,7 @@ [[hotKey keyCombo] modifiers], hotKeyID, GetEventDispatcherTarget(), - nil, + 0, &carbonHotKey ); if( err ) @@ -254,7 +254,7 @@ NSAssert( hotKeyID.signature == 'PTHk', @"Invalid hot key id" ); - NSAssert( hotKeyID.id != nil, @"Invalid hot key id" ); + NSAssert( hotKeyID.id != 0, @"Invalid hot key id" ); hotKey = (PTHotKey*)hotKeyID.id; diff -u /Users/chris/Downloads/HotKeysLib3/PTHotKeysLib/src/PTKeyCodeTranslator.h src/PTKeyCodeTranslator.h --- /Users/chris/Downloads/HotKeysLib3/PTHotKeysLib/src/PTKeyCodeTranslator.h 2005-11-28 01:25:06.000000000 -0500 +++ src/PTKeyCodeTranslator.h 2008-05-04 20:46:12.000000000 -0400 @@ -12,19 +12,17 @@ @interface PTKeyCodeTranslator : NSObject { - KeyboardLayoutRef keyboardLayout; - UCKeyboardLayout *uchrData; - void *KCHRData; - SInt32 keyLayoutKind; + TISInputSourceRef keyboardLayout; + const UCKeyboardLayout *uchrData; UInt32 keyTranslateState; UInt32 deadKeyState; } + (id)currentTranslator; -- (id)initWithKeyboardLayout:(KeyboardLayoutRef)aLayout; +- (id)initWithKeyboardLayout:(TISInputSourceRef)aLayout; - (NSString *)translateKeyCode:(short)keyCode; -- (KeyboardLayoutRef)keyboardLayout; +- (TISInputSourceRef)keyboardLayout; @end diff -u /Users/chris/Downloads/HotKeysLib3/PTHotKeysLib/src/PTKeyCodeTranslator.m src/PTKeyCodeTranslator.m --- /Users/chris/Downloads/HotKeysLib3/PTHotKeysLib/src/PTKeyCodeTranslator.m 2005-11-28 01:25:06.000000000 -0500 +++ src/PTKeyCodeTranslator.m 2008-05-04 20:46:12.000000000 -0400 @@ -14,9 +14,7 @@ + (id)currentTranslator { static PTKeyCodeTranslator *current = nil; - KeyboardLayoutRef currentLayout; - OSStatus err = KLGetCurrentKeyboardLayout( ¤tLayout ); - if (err != noErr) return nil; + TISInputSourceRef currentLayout = TISCopyCurrentKeyboardLayoutInputSource(); if (current == nil) { current = [[PTKeyCodeTranslator alloc] initWithKeyboardLayout:currentLayout]; @@ -27,53 +25,35 @@ return current; } -- (id)initWithKeyboardLayout:(KeyboardLayoutRef)aLayout +- (id)initWithKeyboardLayout:(TISInputSourceRef)aLayout { if ((self = [super init]) != nil) { - OSStatus err; keyboardLayout = aLayout; - err = KLGetKeyboardLayoutProperty( aLayout, kKLKind, (const void **)&keyLayoutKind ); - if (err != noErr) return nil; - - if (keyLayoutKind == kKLKCHRKind) { - err = KLGetKeyboardLayoutProperty( keyboardLayout, kKLKCHRData, (const void **)&KCHRData ); - if (err != noErr) return nil; - } else { - err = KLGetKeyboardLayoutProperty( keyboardLayout, kKLuchrData, (const void **)&uchrData ); - if (err != noErr) return nil; - } + CFDataRef uchr = TISGetInputSourceProperty( keyboardLayout , kTISPropertyUnicodeKeyLayoutData ); + uchrData = ( const UCKeyboardLayout* )CFDataGetBytePtr(uchr); } return self; } - (NSString *)translateKeyCode:(short)keyCode { - if (keyLayoutKind == kKLKCHRKind) { - UInt32 charCode = KeyTranslate( KCHRData, keyCode, &keyTranslateState ); - char theChar = (charCode & 0x00FF); - return [[[NSString alloc] initWithData:[NSData dataWithBytes:&theChar length:1] encoding:NSMacOSRomanStringEncoding] autorelease]; - } else { - UniCharCount maxStringLength = 4, actualStringLength; - UniChar unicodeString[4]; - OSStatus err; - err = UCKeyTranslate( uchrData, keyCode, kUCKeyActionDisplay, 0, LMGetKbdType(), kUCKeyTranslateNoDeadKeysBit, &deadKeyState, maxStringLength, &actualStringLength, unicodeString ); - return [NSString stringWithCharacters:unicodeString length:1]; - } + UniCharCount maxStringLength = 4, actualStringLength; + UniChar unicodeString[4]; + OSStatus err; + err = UCKeyTranslate( uchrData, keyCode, kUCKeyActionDisplay, 0, LMGetKbdType(), kUCKeyTranslateNoDeadKeysBit, &deadKeyState, maxStringLength, &actualStringLength, unicodeString ); + return [NSString stringWithCharacters:unicodeString length:1]; } -- (KeyboardLayoutRef)keyboardLayout { +- (TISInputSourceRef)keyboardLayout { return keyboardLayout; } - (NSString *)description { NSString *kind; - if (keyLayoutKind == kKLKCHRKind) - kind = @"KCHR"; - else - kind = @"uchr"; + kind = @"uchr"; NSString *layoutName; - KLGetKeyboardLayoutProperty( keyboardLayout, kKLLocalizedName, (const void **)&layoutName ); + layoutName = TISGetInputSourceProperty( keyboardLayout, kTISPropertyLocalizedName ); return [NSString stringWithFormat:@"PTKeyCodeTranslator layout=%@ (%@)", layoutName, kind]; } diff -u /Users/chris/Downloads/HotKeysLib3/PTHotKeysLib/src/PTKeyCombo.h src/PTKeyCombo.h --- /Users/chris/Downloads/HotKeysLib3/PTHotKeysLib/src/PTKeyCombo.h 2005-11-28 01:25:06.000000000 -0500 +++ src/PTKeyCombo.h 2008-05-04 20:46:12.000000000 -0400 @@ -39,5 +39,7 @@ @interface PTKeyCombo (UserDisplayAdditions) - (NSString*)description; +- (NSString*)keyCodeString; +- (NSUInteger)modifierMask; @end diff -u /Users/chris/Downloads/HotKeysLib3/PTHotKeysLib/src/PTKeyCombo.m src/PTKeyCombo.m --- /Users/chris/Downloads/HotKeysLib3/PTHotKeysLib/src/PTKeyCombo.m 2008-04-30 16:45:54.000000000 -0400 +++ src/PTKeyCombo.m 2008-05-04 20:46:12.000000000 -0400 @@ -197,6 +197,39 @@ return [self _stringForKeyCode: keyCode newKeyCodeMap: dict]; } +- (NSString*)keyCodeString +{ + // special case: the modifiers for the "clear" key are 0x0 + if ( [self isClearCombo] ) return @""; + + return [[self class] _stringForKeyCode:[self keyCode]]; +} + +- (NSUInteger)modifierMask +{ + // special case: the modifiers for the "clear" key are 0x0 + if ( [self isClearCombo] ) return 0; + + static NSUInteger modToChar[4][2] = + { + { cmdKey, NSCommandKeyMask }, + { optionKey, NSAlternateKeyMask }, + { controlKey, NSControlKeyMask }, + { shiftKey, NSShiftKeyMask } + }; + + NSUInteger i, ret = 0; + + for ( i = 0; i < 4; i++ ) + { + if ( [self modifiers] & modToChar[i][0] ) { + ret |= modToChar[i][1]; + } + } + + return ret; +} + - (NSString*)description { NSString* desc;