4 // Created by Quentin Carnicelli on Sun Aug 03 2003.
5 // Copyright (c) 2003 iThink Software. All rights reserved.
8 #import "ITKeyBroadcaster.h"
10 #import <Carbon/Carbon.h>
12 NSString* ITKeyBroadcasterKeyEvent = @"ITKeyBroadcasterKeyEvent";
14 @implementation ITKeyBroadcaster
16 - (void)_bcastKeyCode: (short)keyCode modifiers: (long)modifiers
18 ITKeyCombo* keyCombo = [ITKeyCombo keyComboWithKeyCode: keyCode modifiers: modifiers];
19 NSDictionary* userInfo = [NSDictionary dictionaryWithObject: keyCombo forKey:@"keyCombo"];
21 [[NSNotificationCenter defaultCenter]
22 postNotificationName: ITKeyBroadcasterKeyEvent
27 - (void)_bcastEvent: (NSEvent*)event
32 keyCode = [event keyCode];
33 modifiers = [event modifierFlags];
34 modifiers = [[self class] cocoaModifiersAsCarbonModifiers: modifiers];
36 [self _bcastKeyCode: keyCode modifiers: modifiers];
39 - (void)keyDown: (NSEvent*)event
41 [self _bcastEvent: event];
44 - (BOOL)performKeyEquivalent: (NSEvent*)event
46 [self _bcastEvent: event];
50 + (long)cocoaModifiersAsCarbonModifiers: (long)cocoaModifiers
52 static long cocoaToCarbon[6][2] =
54 { NSCommandKeyMask, cmdKey},
55 { NSAlternateKeyMask, optionKey},
56 { NSControlKeyMask, controlKey},
57 { NSShiftKeyMask, shiftKey},
58 { NSFunctionKeyMask, rightControlKey},
59 //{ NSAlphaShiftKeyMask, alphaLock }, //Ignore this?
62 long carbonModifiers = 0;
65 for( i = 0 ; i < 6; i++ )
66 if( cocoaModifiers & cocoaToCarbon[i][0] )
67 carbonModifiers += cocoaToCarbon[i][1];
69 return carbonModifiers;