Moved NDHotKey to its own framework, and removed useless Edit buttons from the hotkeys preference pane

CQTexperiment
Chris Moeller 2013-10-11 09:37:45 -07:00
parent 2fe9e86eb9
commit 8cf6b86ba2
26 changed files with 2548 additions and 3485 deletions

View File

@ -2,7 +2,7 @@
#import <Cocoa/Cocoa.h>
#import "NDHotKeyEvent.h"
#import <NDHotKey/NDHotKeyEvent.h>
#import "NowPlayingBarController.h"
@class FileTreeViewController;

View File

@ -4,7 +4,7 @@
#import "PlaylistController.h"
#import "PlaylistView.h"
#import "PlaylistEntry.h"
#import "NDHotKeyEvent.h"
#import <NDHotKey/NDHotKeyEvent.h>
#import "AppleRemote.h"
#import "PlaylistLoader.h"
#import "OpenURLPanel.h"
@ -451,15 +451,15 @@ increase/decrease as long as the user holds the left/right, plus/minus button */
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:35] forKey:@"hotKeyPlayKeyCode"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:(NSControlKeyMask|NSCommandKeyMask)] forKey:@"hotKeyPlayModifiers"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:'P'] forKey:@"hotKeyPlayCharacter"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:45] forKey:@"hotKeyNextKeyCode"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:(NSControlKeyMask|NSCommandKeyMask)] forKey:@"hotKeyNextModifiers"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:'N'] forKey:@"hotKeyNextCharacter"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:15] forKey:@"hotKeyPreviousKeyCode"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:(NSControlKeyMask|NSCommandKeyMask)] forKey:@"hotKeyPreviousModifiers"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:'R'] forKey:@"hotKeyPreviousCharacter"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:8] forKey:@"hotKeySpamKeyCode"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:(NSControlKeyMask|NSCommandKeyMask)] forKey:@"hotKeySpamModifiers"];
[userDefaultsValuesDict setObject:[NSNumber numberWithBool:YES] forKey:@"remoteEnabled"];
[userDefaultsValuesDict setObject:[NSNumber numberWithBool:YES] forKey:@"remoteOnlyOnActive"];
@ -472,19 +472,6 @@ increase/decrease as long as the user holds the left/right, plus/minus button */
[userDefaultsValuesDict setObject:@"albumGainWithPeak" forKey:@"volumeScaling"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:0] forKey:@"hotKeyPlayKeyCode"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:0] forKey:@"hotKeyPlayCharacter"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:0] forKey:@"hotKeyPlayModifiers"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:0] forKey:@"hotKeyNextKeyCode"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:0] forKey:@"hotKeyNextCharacter"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:0] forKey:@"hotKeyNextModifiers"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:0] forKey:@"hotKeyPreviousKeyCode"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:0] forKey:@"hotKeyPreviousCharacter"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:0] forKey:@"hotKeyPreviousModifiers"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:0] forKey:@"hotKeySpamKeyCode"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:0] forKey:@"hotKeySpamCharacter"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:0] forKey:@"hotKeySpamModifiers"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInteger:kCogStatusStopped] forKey:@"lastPlaybackStatus"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInteger:-1] forKey:@"lastTrackPlaying"];
[userDefaultsValuesDict setObject:[NSNumber numberWithDouble:0] forKey:@"lastTrackPosition"];
@ -543,7 +530,6 @@ increase/decrease as long as the user holds the left/right, plus/minus button */
if ([[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"hotKeyPlayKeyCode"] intValue]) {
playHotKey = [[NDHotKeyEvent alloc]
initWithKeyCode: [[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"hotKeyPlayKeyCode"] intValue]
character: [[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"hotKeyPlayCharacter"] intValue]
modifierFlags: [[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"hotKeyPlayModifiers"] intValue]
];
[playHotKey setTarget:self selector:@selector(clickPlay)];
@ -554,7 +540,6 @@ increase/decrease as long as the user holds the left/right, plus/minus button */
if ([[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"hotKeyPreviousKeyCode"] intValue]) {
prevHotKey = [[NDHotKeyEvent alloc]
initWithKeyCode: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyPreviousKeyCode"]
character: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyPreviousCharacter"]
modifierFlags: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyPreviousModifiers"]
];
[prevHotKey setTarget:self selector:@selector(clickPrev)];
@ -565,7 +550,6 @@ increase/decrease as long as the user holds the left/right, plus/minus button */
if ([[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"hotKeyNextKeyCode"] intValue]) {
nextHotKey = [[NDHotKeyEvent alloc]
initWithKeyCode: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyNextKeyCode"]
character: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyNextCharacter"]
modifierFlags: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyNextModifiers"]
];
[nextHotKey setTarget:self selector:@selector(clickNext)];
@ -576,7 +560,6 @@ increase/decrease as long as the user holds the left/right, plus/minus button */
if ([[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"hotKeySpamKeyCode"] intValue]) {
spamHotKey = [[NDHotKeyEvent alloc]
initWithKeyCode: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeySpamKeyCode"]
character: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeySpamCharacter"]
modifierFlags: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeySpamModifiers"]
];
[spamHotKey setTarget:self selector:@selector(clickSpam)];

View File

@ -45,8 +45,6 @@
1778D3CA0F645BF00037E7A0 /* MissingAlbumArtTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 1778D3C90F645BF00037E7A0 /* MissingAlbumArtTransformer.m */; };
177EBFA20B8BC2A70000BC8C /* AppleRemote.m in Sources */ = {isa = PBXBuildFile; fileRef = 177EBF7F0B8BC2A70000BC8C /* AppleRemote.m */; };
177EBFA70B8BC2A70000BC8C /* ImageTextCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 177EBF870B8BC2A70000BC8C /* ImageTextCell.m */; };
177EBFAB0B8BC2A70000BC8C /* NDHotKeyControl.m in Sources */ = {isa = PBXBuildFile; fileRef = 177EBF8D0B8BC2A70000BC8C /* NDHotKeyControl.m */; };
177EBFAD0B8BC2A70000BC8C /* NDHotKeyEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 177EBF8F0B8BC2A70000BC8C /* NDHotKeyEvent.m */; };
177EC0270B8BC2CF0000BC8C /* TrackingCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 177EC01B0B8BC2CF0000BC8C /* TrackingCell.m */; };
177EC0290B8BC2CF0000BC8C /* TrackingSlider.m in Sources */ = {isa = PBXBuildFile; fileRef = 177EC01D0B8BC2CF0000BC8C /* TrackingSlider.m */; };
177EC04B0B8BC2FF0000BC8C /* next.png in Resources */ = {isa = PBXBuildFile; fileRef = 177EC0350B8BC2FF0000BC8C /* next.png */; };
@ -177,6 +175,8 @@
83849172180843B200E7332D /* pauseDockBadgeColorful.png in Resources */ = {isa = PBXBuildFile; fileRef = 8384916F180843B200E7332D /* pauseDockBadgeColorful.png */; };
83849173180843B200E7332D /* playDockBadgeColorful.png in Resources */ = {isa = PBXBuildFile; fileRef = 83849170180843B200E7332D /* playDockBadgeColorful.png */; };
83849174180843B200E7332D /* stopDockBadgeColorful.png in Resources */ = {isa = PBXBuildFile; fileRef = 83849171180843B200E7332D /* stopDockBadgeColorful.png */; };
838491871808591F00E7332D /* NDHotKey.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8384917E1808585D00E7332D /* NDHotKey.framework */; };
838491881808593200E7332D /* NDHotKey.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 8384917E1808585D00E7332D /* NDHotKey.framework */; };
8399D4E21805A55000B503B1 /* XmlContainer.m in Sources */ = {isa = PBXBuildFile; fileRef = 8399D4E01805A55000B503B1 /* XmlContainer.m */; };
83BCB8DE17FC971300760340 /* FFMPEG.bundle in CopyFiles */ = {isa = PBXBuildFile; fileRef = B09E94350D747F7B0064F138 /* FFMPEG.bundle */; };
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
@ -447,6 +447,20 @@
remoteGlobalIDString = 8375B03B17FFEA400092A79F;
remoteInfo = Opus;
};
8384917D1808585D00E7332D /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 838491791808585C00E7332D /* NDHotKey.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 32F1615614E6BB3B00D6AB2F;
remoteInfo = NDHotKey;
};
838491851808591400E7332D /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 838491791808585C00E7332D /* NDHotKey.xcodeproj */;
proxyType = 1;
remoteGlobalIDString = 32F1615514E6BB3B00D6AB2F;
remoteInfo = NDHotKey;
};
83BCB8D817FC96F800760340 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 8360EF0017F92B23005208A4 /* HighlyComplete.xcodeproj */;
@ -542,6 +556,7 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
838491881808593200E7332D /* NDHotKey.framework in CopyFiles */,
17F561400C3BD4F30019975C /* CogAudio.framework in CopyFiles */,
170680840B950164006BA573 /* Growl.framework in CopyFiles */,
);
@ -611,10 +626,6 @@
177EBF7F0B8BC2A70000BC8C /* AppleRemote.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = AppleRemote.m; sourceTree = "<group>"; };
177EBF860B8BC2A70000BC8C /* ImageTextCell.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ImageTextCell.h; sourceTree = "<group>"; };
177EBF870B8BC2A70000BC8C /* ImageTextCell.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = ImageTextCell.m; sourceTree = "<group>"; };
177EBF8C0B8BC2A70000BC8C /* NDHotKeyControl.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = NDHotKeyControl.h; sourceTree = "<group>"; };
177EBF8D0B8BC2A70000BC8C /* NDHotKeyControl.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = NDHotKeyControl.m; sourceTree = "<group>"; };
177EBF8E0B8BC2A70000BC8C /* NDHotKeyEvent.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = NDHotKeyEvent.h; sourceTree = "<group>"; };
177EBF8F0B8BC2A70000BC8C /* NDHotKeyEvent.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = NDHotKeyEvent.m; sourceTree = "<group>"; };
177EC01A0B8BC2CF0000BC8C /* TrackingCell.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = TrackingCell.h; sourceTree = "<group>"; };
177EC01B0B8BC2CF0000BC8C /* TrackingCell.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = TrackingCell.m; sourceTree = "<group>"; };
177EC01C0B8BC2CF0000BC8C /* TrackingSlider.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = TrackingSlider.h; sourceTree = "<group>"; };
@ -797,6 +808,7 @@
8384916F180843B200E7332D /* pauseDockBadgeColorful.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = pauseDockBadgeColorful.png; path = Images/pauseDockBadgeColorful.png; sourceTree = "<group>"; };
83849170180843B200E7332D /* playDockBadgeColorful.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = playDockBadgeColorful.png; path = Images/playDockBadgeColorful.png; sourceTree = "<group>"; };
83849171180843B200E7332D /* stopDockBadgeColorful.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = stopDockBadgeColorful.png; path = Images/stopDockBadgeColorful.png; sourceTree = "<group>"; };
838491791808585C00E7332D /* NDHotKey.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = NDHotKey.xcodeproj; path = Frameworks/NDHotKey/NDHotKey.xcodeproj; sourceTree = "<group>"; };
8399D4E01805A55000B503B1 /* XmlContainer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XmlContainer.m; sourceTree = "<group>"; };
8399D4E11805A55000B503B1 /* XmlContainer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XmlContainer.h; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
@ -836,6 +848,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
838491871808591F00E7332D /* NDHotKey.framework in Frameworks */,
8355D6B8180613FB00D05687 /* Security.framework in Frameworks */,
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */,
8E6889240AAA403C00AD3950 /* Carbon.framework in Frameworks */,
@ -884,6 +897,7 @@
1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = {
isa = PBXGroup;
children = (
838491791808585C00E7332D /* NDHotKey.xcodeproj */,
17F5612A0C3BD4DC0019975C /* CogAudio.xcodeproj */,
170680620B950158006BA573 /* Growl.framework */,
8E6889230AAA403C00AD3950 /* Carbon.framework */,
@ -951,7 +965,6 @@
177EBF7D0B8BC2A70000BC8C /* AppleRemote */,
177EBF850B8BC2A70000BC8C /* ImageTextCell */,
179790DD0C087AB7001D6996 /* OpenURLPanel */,
177EBF8B0B8BC2A70000BC8C /* NDHotKeys */,
);
path = ThirdParty;
sourceTree = "<group>";
@ -974,17 +987,6 @@
path = ImageTextCell;
sourceTree = "<group>";
};
177EBF8B0B8BC2A70000BC8C /* NDHotKeys */ = {
isa = PBXGroup;
children = (
177EBF8C0B8BC2A70000BC8C /* NDHotKeyControl.h */,
177EBF8D0B8BC2A70000BC8C /* NDHotKeyControl.m */,
177EBF8E0B8BC2A70000BC8C /* NDHotKeyEvent.h */,
177EBF8F0B8BC2A70000BC8C /* NDHotKeyEvent.m */,
);
path = NDHotKeys;
sourceTree = "<group>";
};
177EC0110B8BC2CF0000BC8C /* Utils */ = {
isa = PBXGroup;
children = (
@ -1445,6 +1447,14 @@
name = Products;
sourceTree = "<group>";
};
8384917A1808585C00E7332D /* Products */ = {
isa = PBXGroup;
children = (
8384917E1808585D00E7332D /* NDHotKey.framework */,
);
name = Products;
sourceTree = "<group>";
};
8E07AAEA0AAC90DC00A4B32F /* Preferences */ = {
isa = PBXGroup;
children = (
@ -1579,6 +1589,7 @@
buildRules = (
);
dependencies = (
838491861808591400E7332D /* PBXTargetDependency */,
8375B36217FFEF010092A79F /* PBXTargetDependency */,
8375B36417FFEF010092A79F /* PBXTargetDependency */,
83BCB8DD17FC96FC00760340 /* PBXTargetDependency */,
@ -1692,6 +1703,10 @@
ProductGroup = 17C8089F0C3BD1AB005707C4 /* Products */;
ProjectRef = 17C8089E0C3BD1AB005707C4 /* Musepack.xcodeproj */;
},
{
ProductGroup = 8384917A1808585C00E7332D /* Products */;
ProjectRef = 838491791808585C00E7332D /* NDHotKey.xcodeproj */;
},
{
ProductGroup = 8375B05217FFEA400092A79F /* Products */;
ProjectRef = 8375B05117FFEA400092A79F /* Opus.xcodeproj */;
@ -1851,6 +1866,13 @@
remoteRef = 8375B05617FFEA410092A79F /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
8384917E1808585D00E7332D /* NDHotKey.framework */ = {
isa = PBXReferenceProxy;
fileType = wrapper.framework;
path = NDHotKey.framework;
remoteRef = 8384917D1808585D00E7332D /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
8E8D40870CBB036600135C1B /* M3u.bundle */ = {
isa = PBXReferenceProxy;
fileType = wrapper.cfbundle;
@ -1997,8 +2019,6 @@
8E07AB790AAC930B00A4B32F /* PreferencesController.m in Sources */,
177EBFA20B8BC2A70000BC8C /* AppleRemote.m in Sources */,
177EBFA70B8BC2A70000BC8C /* ImageTextCell.m in Sources */,
177EBFAB0B8BC2A70000BC8C /* NDHotKeyControl.m in Sources */,
177EBFAD0B8BC2A70000BC8C /* NDHotKeyEvent.m in Sources */,
177EC0270B8BC2CF0000BC8C /* TrackingCell.m in Sources */,
177EC0290B8BC2CF0000BC8C /* TrackingSlider.m in Sources */,
1770429C0B8BC53600B86321 /* AppController.m in Sources */,
@ -2158,6 +2178,11 @@
name = Opus;
targetProxy = 8375B36317FFEF010092A79F /* PBXContainerItemProxy */;
};
838491861808591400E7332D /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
name = NDHotKey;
targetProxy = 838491851808591400E7332D /* PBXContainerItemProxy */;
};
83BCB8D917FC96F800760340 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
name = HighlyComplete;

View File

@ -0,0 +1,311 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objects = {
/* Begin PBXBuildFile section */
32F1615A14E6BB3B00D6AB2F /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 32F1615914E6BB3B00D6AB2F /* Cocoa.framework */; };
32F1616414E6BB3B00D6AB2F /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 32F1616214E6BB3B00D6AB2F /* InfoPlist.strings */; };
32F1617A14E6BBFC00D6AB2F /* NDHotKeyControl.h in Headers */ = {isa = PBXBuildFile; fileRef = 32F1617414E6BBFC00D6AB2F /* NDHotKeyControl.h */; settings = {ATTRIBUTES = (Public, ); }; };
32F1617B14E6BBFC00D6AB2F /* NDHotKeyControl.m in Sources */ = {isa = PBXBuildFile; fileRef = 32F1617514E6BBFC00D6AB2F /* NDHotKeyControl.m */; };
32F1617C14E6BBFC00D6AB2F /* NDHotKeyEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 32F1617614E6BBFC00D6AB2F /* NDHotKeyEvent.h */; settings = {ATTRIBUTES = (Public, ); }; };
32F1617D14E6BBFC00D6AB2F /* NDHotKeyEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 32F1617714E6BBFC00D6AB2F /* NDHotKeyEvent.m */; };
32F1617E14E6BBFC00D6AB2F /* NDKeyboardLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 32F1617814E6BBFC00D6AB2F /* NDKeyboardLayout.h */; settings = {ATTRIBUTES = (Public, ); }; };
32F1617F14E6BBFC00D6AB2F /* NDKeyboardLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 32F1617914E6BBFC00D6AB2F /* NDKeyboardLayout.m */; };
32F1618E14E6BE7300D6AB2F /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 32F1618D14E6BE7300D6AB2F /* Carbon.framework */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
32F1615614E6BB3B00D6AB2F /* NDHotKey.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = NDHotKey.framework; sourceTree = BUILT_PRODUCTS_DIR; };
32F1615914E6BB3B00D6AB2F /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
32F1615C14E6BB3B00D6AB2F /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
32F1615D14E6BB3B00D6AB2F /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
32F1615E14E6BB3B00D6AB2F /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
32F1616114E6BB3B00D6AB2F /* NDHotKey-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "NDHotKey-Info.plist"; sourceTree = "<group>"; };
32F1616314E6BB3B00D6AB2F /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
32F1616514E6BB3B00D6AB2F /* NDHotKey-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NDHotKey-Prefix.pch"; sourceTree = "<group>"; };
32F1617414E6BBFC00D6AB2F /* NDHotKeyControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NDHotKeyControl.h; sourceTree = "<group>"; };
32F1617514E6BBFC00D6AB2F /* NDHotKeyControl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NDHotKeyControl.m; sourceTree = "<group>"; };
32F1617614E6BBFC00D6AB2F /* NDHotKeyEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NDHotKeyEvent.h; sourceTree = "<group>"; };
32F1617714E6BBFC00D6AB2F /* NDHotKeyEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NDHotKeyEvent.m; sourceTree = "<group>"; };
32F1617814E6BBFC00D6AB2F /* NDKeyboardLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NDKeyboardLayout.h; sourceTree = "<group>"; };
32F1617914E6BBFC00D6AB2F /* NDKeyboardLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NDKeyboardLayout.m; sourceTree = "<group>"; };
32F1618D14E6BE7300D6AB2F /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = System/Library/Frameworks/Carbon.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
32F1615214E6BB3B00D6AB2F /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
32F1618E14E6BE7300D6AB2F /* Carbon.framework in Frameworks */,
32F1615A14E6BB3B00D6AB2F /* Cocoa.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
32F1614A14E6BB3B00D6AB2F = {
isa = PBXGroup;
children = (
32F1618D14E6BE7300D6AB2F /* Carbon.framework */,
32F1615F14E6BB3B00D6AB2F /* NDHotKey */,
32F1615814E6BB3B00D6AB2F /* Frameworks */,
32F1615714E6BB3B00D6AB2F /* Products */,
);
sourceTree = "<group>";
};
32F1615714E6BB3B00D6AB2F /* Products */ = {
isa = PBXGroup;
children = (
32F1615614E6BB3B00D6AB2F /* NDHotKey.framework */,
);
name = Products;
sourceTree = "<group>";
};
32F1615814E6BB3B00D6AB2F /* Frameworks */ = {
isa = PBXGroup;
children = (
32F1615914E6BB3B00D6AB2F /* Cocoa.framework */,
32F1615B14E6BB3B00D6AB2F /* Other Frameworks */,
);
name = Frameworks;
sourceTree = "<group>";
};
32F1615B14E6BB3B00D6AB2F /* Other Frameworks */ = {
isa = PBXGroup;
children = (
32F1615C14E6BB3B00D6AB2F /* AppKit.framework */,
32F1615D14E6BB3B00D6AB2F /* CoreData.framework */,
32F1615E14E6BB3B00D6AB2F /* Foundation.framework */,
);
name = "Other Frameworks";
sourceTree = "<group>";
};
32F1615F14E6BB3B00D6AB2F /* NDHotKey */ = {
isa = PBXGroup;
children = (
32F1617414E6BBFC00D6AB2F /* NDHotKeyControl.h */,
32F1617514E6BBFC00D6AB2F /* NDHotKeyControl.m */,
32F1617614E6BBFC00D6AB2F /* NDHotKeyEvent.h */,
32F1617714E6BBFC00D6AB2F /* NDHotKeyEvent.m */,
32F1617814E6BBFC00D6AB2F /* NDKeyboardLayout.h */,
32F1617914E6BBFC00D6AB2F /* NDKeyboardLayout.m */,
32F1616014E6BB3B00D6AB2F /* Supporting Files */,
);
path = NDHotKey;
sourceTree = "<group>";
};
32F1616014E6BB3B00D6AB2F /* Supporting Files */ = {
isa = PBXGroup;
children = (
32F1616114E6BB3B00D6AB2F /* NDHotKey-Info.plist */,
32F1616214E6BB3B00D6AB2F /* InfoPlist.strings */,
32F1616514E6BB3B00D6AB2F /* NDHotKey-Prefix.pch */,
);
name = "Supporting Files";
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXHeadersBuildPhase section */
32F1615314E6BB3B00D6AB2F /* Headers */ = {
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
32F1617A14E6BBFC00D6AB2F /* NDHotKeyControl.h in Headers */,
32F1617C14E6BBFC00D6AB2F /* NDHotKeyEvent.h in Headers */,
32F1617E14E6BBFC00D6AB2F /* NDKeyboardLayout.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXHeadersBuildPhase section */
/* Begin PBXNativeTarget section */
32F1615514E6BB3B00D6AB2F /* NDHotKey */ = {
isa = PBXNativeTarget;
buildConfigurationList = 32F1616B14E6BB3B00D6AB2F /* Build configuration list for PBXNativeTarget "NDHotKey" */;
buildPhases = (
32F1615114E6BB3B00D6AB2F /* Sources */,
32F1615214E6BB3B00D6AB2F /* Frameworks */,
32F1615314E6BB3B00D6AB2F /* Headers */,
32F1615414E6BB3B00D6AB2F /* Resources */,
);
buildRules = (
);
dependencies = (
);
name = NDHotKey;
productName = NDHotKey;
productReference = 32F1615614E6BB3B00D6AB2F /* NDHotKey.framework */;
productType = "com.apple.product-type.framework";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
32F1614C14E6BB3B00D6AB2F /* Project object */ = {
isa = PBXProject;
attributes = {
ORGANIZATIONNAME = "dmitry.promsky@gmail.com";
};
buildConfigurationList = 32F1614F14E6BB3B00D6AB2F /* Build configuration list for PBXProject "NDHotKey" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
);
mainGroup = 32F1614A14E6BB3B00D6AB2F;
productRefGroup = 32F1615714E6BB3B00D6AB2F /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
32F1615514E6BB3B00D6AB2F /* NDHotKey */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
32F1615414E6BB3B00D6AB2F /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
32F1616414E6BB3B00D6AB2F /* InfoPlist.strings in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
32F1615114E6BB3B00D6AB2F /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
32F1617B14E6BBFC00D6AB2F /* NDHotKeyControl.m in Sources */,
32F1617D14E6BBFC00D6AB2F /* NDHotKeyEvent.m in Sources */,
32F1617F14E6BBFC00D6AB2F /* NDKeyboardLayout.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXVariantGroup section */
32F1616214E6BB3B00D6AB2F /* InfoPlist.strings */ = {
isa = PBXVariantGroup;
children = (
32F1616314E6BB3B00D6AB2F /* en */,
);
name = InfoPlist.strings;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
/* Begin XCBuildConfiguration section */
32F1616914E6BB3B00D6AB2F /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
COPY_PHASE_STRIP = NO;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.7;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx10.7;
SYMROOT = ../../build;
};
name = Debug;
};
32F1616A14E6BB3B00D6AB2F /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.7;
SDKROOT = macosx10.7;
SYMROOT = ../../build;
};
name = Release;
};
32F1616C14E6BB3B00D6AB2F /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
FRAMEWORK_VERSION = A;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "NDHotKey/NDHotKey-Prefix.pch";
INFOPLIST_FILE = "NDHotKey/NDHotKey-Info.plist";
INSTALL_PATH = "@loader_path/../Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
WRAPPER_EXTENSION = framework;
};
name = Debug;
};
32F1616D14E6BB3B00D6AB2F /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
FRAMEWORK_VERSION = A;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "NDHotKey/NDHotKey-Prefix.pch";
INFOPLIST_FILE = "NDHotKey/NDHotKey-Info.plist";
INSTALL_PATH = "@loader_path/../Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
WRAPPER_EXTENSION = framework;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
32F1614F14E6BB3B00D6AB2F /* Build configuration list for PBXProject "NDHotKey" */ = {
isa = XCConfigurationList;
buildConfigurations = (
32F1616914E6BB3B00D6AB2F /* Debug */,
32F1616A14E6BB3B00D6AB2F /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
32F1616B14E6BB3B00D6AB2F /* Build configuration list for PBXNativeTarget "NDHotKey" */ = {
isa = XCConfigurationList;
buildConfigurations = (
32F1616C14E6BB3B00D6AB2F /* Debug */,
32F1616D14E6BB3B00D6AB2F /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 32F1614C14E6BB3B00D6AB2F /* Project object */;
}

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>ND.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2012 dmitry.promsky@gmail.com. All rights reserved.</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>

View File

@ -0,0 +1,7 @@
//
// Prefix header for all source files of the 'NDHotKey' target in the 'NDHotKey' project
//
#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#endif

View File

@ -0,0 +1,128 @@
/*
NDHotKeyControl.h
Created by Nathan Day on 29.03.08 under a MIT-style license.
Copyright (c) 2008 Nathan Day
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/*!
@header NDHotKeyControl.h
@abstract Header file for a subclass of NSTextField for getting hot key combinations from the user.
@discussion The <tt>NDHotKeyControl</tt> can be used to get a <tt>NDHotKeyEvent</tt> for the last key combination pressed by the user.
@updated 2010-01-18
*/
#import <AppKit/AppKit.h>
@class NDHotKeyEvent;
/*!
@class NDHotKeyControl
@abstract Subclass of NSTextField for getting hot key combinations from the user.
@discussion The <tt>NDHotKeyControl</tt> can be used to get a <tt>NDHotKeyEvent</tt> for the last key combination pressed by the user.
*/
@interface NDHotKeyControl : NSTextField
{
@private
UInt16 keyCode;
NSUInteger modifierFlags;
BOOL requiresModifierKeys,
readyForEvent,
stayReadyForEvent;
id lastReadyForEventSender;
}
- (IBAction)readyForHotKeyEventChanged:(id)sender;
/*!
@method keyCode
@abstract Get key code.
@discussion Returns the key code for the last key combination the user pressed while the reciever was active.
@result A <tt>UInt16</tt> containing key code.
*/
- (UInt16)keyCode;
/*!
@method keyCharacter
@abstract Get unicode character.
@discussion Returns the unicode character for the last key combination the user pressed while the reciever was active.
@result A <tt>unichar</tt> containing character.
*/
- (unichar)keyCharacter;
/*!
@method modifierFlags
@abstract Get modifer flags.
@discussion Returns the modifer flags for the last key combination the user pressed while the reciever was active.
@result A <tt>unsigned long</tt> containing modifer flags.
*/
- (NSUInteger)modifierFlags;
/*!
@method hotKeyEvent
@abstract Get <tt>NDHotKeyEvent</tt>
@discussion Returns the <tt>NDHotKeyEvent</tt> instance for the last key combination the user pressed while the reciever was active. The <tt>NDHotKeyEvent</tt> returned will either be one that has already been created or a newly created one otherwise.
@result A <tt>NDHotKeyEvent</tt> for the hot key event.
*/
- (NDHotKeyEvent *)hotKeyEvent;
/*!
@method setRequiresModifierKeys:
@abstract Set whether hot keys entered need modifiers keys.
@discussion This does not include function key which do not require modifier keys no matter what the value you pass for the argument <tt><i>flag</i></tt>
@param flag If <tt>NO</tt> then the reciever only accepts hot keys combination containing modifer keys.
*/
- (void)setRequiresModifierKeys:(BOOL)flag;
/*!
@method requiresModifierKeys
@abstract Returns whether hot keys entered need modifiers keys.
@discussion This does not include key which do not require modifier keys no matter what the value is returned.
@result If <tt>NO</tt> then the reciever only accepts hot keys combination containing modifer keys.
*/
- (BOOL)requiresModifierKeys;
/*!
@method setReadyForHotKeyEvent:
@abstract Set up the control to accept input
@discussion Setting <tt>readyForHotKeyEvent</tt> to <tt>YES</tt> will disable all Hot Key Events and then prepare <tt>NDHotKeyControl</tt> for keyboard input. Setting <tt>readyForHotKeyEvent</tt> to <tt>NO</tt> will re-enables all Hot Key Events and then stops <tt>NDHotKeyControl</tt> for accepting keyboard input.
@param flag <#description#>
*/
- (void)setReadyForHotKeyEvent:(BOOL)flag;
/*!
@method readyForHotKeyEvent
@abstract Is the control set up to accept input
@discussion Returns the current state of <tt>readyForHotKeyEvent</tt> as set by the method <tt>setReadyForHotKeyEvent:</tt>.
*/
- (BOOL)readyForHotKeyEvent;
/*!
@method setStayReadyForEvent:
@abstract Will the control remain continually active.
@discussion By default <tt>NDHotKeyControl</tt> will accept one key and then call <tt>[self setReadyForHotKeyEvent:NO]</tt>, <tt>setStayReadyForEvent:</tt> allows you to change this behaviour so that <tt>NDHotKeyControl</tt> will continue accepting keys until it is manually deactivated.
*/
- (void)setStayReadyForEvent:(BOOL)flag;
/*!
@method stayReadyForEvent
@abstract Will the control remain continually active.
@discussion By default <tt>NDHotKeyControl</tt> will accept one key and then call <tt>[self setReadyForHotKeyEvent:NO]</tt>, if <tt>stayReadyForEvent</tt> returns <tt>YES</tt>, <tt>NDHotKeyControl</tt> will continue accepting keys until it is manually deactivated.
*/
- (BOOL)stayReadyForEvent;
@end

View File

@ -0,0 +1,145 @@
/*
NDHotKeyControl.m
Created by Nathan Day on 21.06.06 under a MIT-style license.
Copyright (c) 2008 Nathan Day
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#import "NDHotKeyControl.h"
#import "NDHotKeyEvent.h"
#import "NDKeyboardLayout.h"
@interface NDHotKeyControl ()
@end
/*
* class implementation NDHotKeyControl
*/
@implementation NDHotKeyControl
- (id)initWithFrame:(NSRect)aFrame
{
if( (self = [super initWithFrame:aFrame]) != nil )
{
[self setEditable:NO];
requiresModifierKeys = YES;
readyForEvent = NO;
stayReadyForEvent = NO;
}
return self;
}
- (id)initWithCoder:(NSCoder *)aCoder
{
if( (self = [super initWithCoder:aCoder]) != nil )
{
[self setEditable:NO];
requiresModifierKeys = YES;
readyForEvent = NO;
stayReadyForEvent = NO;
}
return self;
}
- (IBAction)readyForHotKeyEventChanged:(id)aSender
{
if( [aSender isKindOfClass:[NSMatrix class]] )
aSender = [aSender selectedCell];
if( [aSender isKindOfClass:[NSButton class]] || [aSender isKindOfClass:[NSButtonCell class]] )
{
if( [aSender state] == NSOnState )
{
[self setReadyForHotKeyEvent:YES];
lastReadyForEventSender = aSender;
[self setStringValue:@""];
}
else
{
[self setReadyForHotKeyEvent:NO];
lastReadyForEventSender = nil;
}
}
}
- (unsigned short)keyCode { return keyCode; }
- (unichar)keyCharacter { return [[NDKeyboardLayout keyboardLayout] characterForKeyCode:[self keyCode]]; }
- (NSUInteger)modifierFlags { return modifierFlags; }
- (BOOL)performKeyEquivalent:(NSEvent*)anEvent
{
BOOL theResult = NO;
if( [self readyForHotKeyEvent] )
{
[self keyDown:anEvent];
theResult = YES;
}
else
theResult = [super performKeyEquivalent:anEvent];
return theResult;
}
- (void)keyDown:(NSEvent *)anEvent
{
NSUInteger theModifierFlags = [anEvent modifierFlags];
unichar theChar = [[anEvent charactersIgnoringModifiers] characterAtIndex:0];
theModifierFlags &= (NSShiftKeyMask|NSControlKeyMask|NSAlternateKeyMask|NSCommandKeyMask);
if( (theModifierFlags != 0 || !requiresModifierKeys || theChar > 255) && theChar != 0 )
{
NDKeyboardLayout * theKeyboardLayout = [NDKeyboardLayout keyboardLayout];
NSParameterAssert( theKeyboardLayout != nil );
keyCode = [anEvent keyCode];
modifierFlags = theModifierFlags;
[self setStringValue:[theKeyboardLayout stringForKeyCode:keyCode modifierFlags:modifierFlags]];
[self performClick:self];
if( ![self stayReadyForEvent] )
[self setReadyForHotKeyEvent:NO];
}
}
- (NDHotKeyEvent *)hotKeyEvent { return [NDHotKeyEvent getHotKeyForKeyCode:[self keyCode] modifierFlags:[self modifierFlags]]; }
- (void)setRequiresModifierKeys:(BOOL)aFlag { requiresModifierKeys = aFlag; }
- (BOOL)requiresModifierKeys { return requiresModifierKeys; }
- (void)setReadyForHotKeyEvent:(BOOL)aFlag
{
readyForEvent = aFlag;
[NDHotKeyEvent setAllEnabled:!readyForEvent];
if( readyForEvent == NO && lastReadyForEventSender )
{
[lastReadyForEventSender setState:NSOffState];
lastReadyForEventSender = nil;
}
}
- (BOOL)readyForHotKeyEvent { return readyForEvent; }
- (void)setStayReadyForEvent:(BOOL)aFlag { stayReadyForEvent = aFlag; }
- (BOOL)stayReadyForEvent { return stayReadyForEvent; }
@end

View File

@ -1,3 +1,28 @@
/*
NDHotKeyEvent.h
Created by Nathan Day on 12.06.04 under a MIT-style license.
Copyright (c) 2008 Nathan Day
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/*!
@header NDHotKeyEvent.h
@abstract Header file for the class <tt>NDHotKeyEvent</tt>
@ -6,14 +31,22 @@
<p><h4>Thread Saftey</h4>By default the class object <tt>NDHotKeyEvent</tt> is not thread safe as the underlying functions that it relies on are not thread safe and the mechanism for keeping track of all of the <tt>NDHotKeyEvent</tt> instances is not thread safe either. Thread saftey can be enable be defining the flag <tt>NDHotKeyEventThreadSafe</tt> before compiling.</p>
<p>Even with the flag <tt>NDHotKeyEventThreadSafe</tt> defined instances of <tt>NDHotKeyEvent</tt> will still not be thread safe, that is, it is safe to invoke methods of different instance with different threads as well as class methods, but it is not safe to invoke methods of the same instance with different threads.</p>
<p>The functions <tt>stringForKeyCodeAndModifierFlags</tt> and <tt>unicharForKeyCode</tt> are never thread safe.</p>
<p>Created by Nathan Day on Wed Feb 26 2003.<br>
Copyright &copy; 2002 Nathan Day. All rights reserved.</p>
@updated 2010-01-18
@version 1.1.0
*/
#import <Cocoa/Cocoa.h>
#import <Carbon/Carbon.h>
/*
using NDHashTable clas instead of the NDHashTable functions that existed prior to 10.5 we can support garabage collection easier
*/
#if MAC_OS_X_VERSION_10_5 <= MAC_OS_X_VERSION_MAX_ALLOWED
#define NDMapTableClassDefined
#else
#warning Support for 10.4 and earily has been depreciated
#endif
/*!
@defined NDHotKeyEventThreadSafe
@abstract A flag to enable thread safety.
@ -48,6 +81,7 @@ enum
*/
extern const OSType NDHotKeyDefaultSignature;
@class NDHotKeyEvent;
/*!
@class NDHotKeyEvent
@abstract Class to represent a HotKey
@ -58,13 +92,18 @@ extern const OSType NDHotKeyDefaultSignature;
{
@private
EventHotKeyRef reference;
unsigned short keyCode;
unichar character;
unsigned int modifierFlags;
// UInt16 keyCode;
unichar keyCharacter;
BOOL keyPad;
NSUInteger modifierFlags;
int currentEventType;
id target;
id target;
SEL selectorReleased,
selectorPressed;
selectorPressed;
#ifdef NS_BLOCKS_AVAILABLE
void (^releasedBlock)(NDHotKeyEvent * e);
void (^pressedBlock)(NDHotKeyEvent * e);
#endif
struct
{
unsigned individual : 1;
@ -80,6 +119,13 @@ extern const OSType NDHotKeyDefaultSignature;
*/
+ (BOOL)install;
/*!
@method uninstall
@abstract Unistall the evenr key handler.
@discussion This method can be called if you want to remove all hot key permanently, without you application having to quit, you do not need to call this method if you application is about to quite.
*/
+ (void)uninstall;
/*!
@method setSignature:
@abstract Set the hot key signature for this application
@ -105,6 +151,15 @@ extern const OSType NDHotKeyDefaultSignature;
*/
+ (BOOL)setAllEnabled:(BOOL)flag;
/*!
@method isEnabledKeyCharacter:modifierFlags:
@abstract Is hot key combination enabled.
@abstract Test to see if a key code and modifier flaf combination are enabled.
@param keyCharacter The key character used by the keyboard.
@param modifierFlags The modifer flags, ( <tt>NSCommandKeyMask</tt>, <tt>NSControlKeyMask</tt>, <tt>NSAlternateKeyMask</tt>, <tt>NSShiftKeyMask</tt>, <tt>NSNumericPadKeyMask</tt> ).
@result Returns <tt>YES</tt> if enabled.
*/
+ (BOOL)isEnabledKeyCharacter:(unichar)keyCharacter modifierFlags:(NSUInteger)modifierFlags;
/*!
@method isEnabledKeyCode:modifierFlags:
@abstract Is hot key combination enabled.
@ -113,18 +168,35 @@ extern const OSType NDHotKeyDefaultSignature;
@param modifierFlags The modifer flags, ( <tt>NSCommandKeyMask</tt>, <tt>NSControlKeyMask</tt>, <tt>NSAlternateKeyMask</tt>, <tt>NSShiftKeyMask</tt> ).
@result Returns <tt>YES</tt> if enabled.
*/
+ (BOOL)isEnabledKeyCode:(unsigned short)keyCode modifierFlags:(unsigned int)modifierFlags;
+ (BOOL)isEnabledKeyCode:(UInt16)keyCode modifierFlags:(NSUInteger)modifierFlags;
/*!
@method getHotKeyForKeyCharacter:modifierFlags:
@abstract Get an <tt>NDHotKeyEvent</tt>
@discussion Gets a <tt>NDHotKeyEvent</tt> for the supplied key code and modifer flags by either finding one that has already been created or by creating a new one..
@param keyCharacter The key character used by the keyboard.
@param modifierFlags The modifer flags, ( <tt>NSCommandKeyMask</tt>, <tt>NSControlKeyMask</tt>, <tt>NSAlternateKeyMask</tt>, <tt>NSShiftKeyMask</tt>, <tt>NSNumericPadKeyMask</tt> ).
@result The <tt>NDHotKeyEvent</tt> obejct or nil if failure.
*/
+ (NDHotKeyEvent *)getHotKeyForKeyCharacter:(unichar)keyCharacter modifierFlags:(NSUInteger)modifierFlags;
/*!
@method getHotKeyForKeyCode:modifierFlags:
@abstract Get an <tt>NDHotKeyEvent</tt>
@discussion Gets a <tt>NDHotKeyEvent</tt> for the supplied key code and modifer flags by either finding one that has already been created or by creating a new one..
@param keyCode The key code used by the keyboard, can vary across hardware.
@param aChar The character, used for display purposes only.
@param modifierFlags The modifer flags, ( <tt>NSCommandKeyMask</tt>, <tt>NSControlKeyMask</tt>, <tt>NSAlternateKeyMask</tt>, <tt>NSShiftKeyMask</tt> ).
@result The <tt>NDHotKeyEvent</tt> obejct or nil if failure.
*/
+ (NDHotKeyEvent *)getHotKeyForKeyCode:(unsigned short)keyCode character:(unichar)aChar modifierFlags:(unsigned int)modifierFlags;
+ (NDHotKeyEvent *)getHotKeyForKeyCode:(UInt16)keyCode modifierFlags:(NSUInteger)modifierFlags;
/*!
@method findHotKeyForKeyCharacter:modifierFlags:
@abstract Find an <tt>NDHotKeyEvent</tt>
@discussion Finds the <tt>NDHotKeyEvent</tt> for the supplied key code and modifer flags.
@param keyCharacter The key character used by the keyboard.
@param modifierFlags The modifer flags, ( <tt>NSCommandKeyMask</tt>, <tt>NSControlKeyMask</tt>, <tt>NSAlternateKeyMask</tt>, <tt>NSShiftKeyMask</tt>, <tt>NSNumericPadKeyMask</tt> ).
@result The <tt>NDHotKeyEvent</tt> obejct or nil if none found.
*/
+ (NDHotKeyEvent *)findHotKeyForKeyCharacter:(unichar)keyCharacter modifierFlags:(NSUInteger)modifierFlags;
/*!
@method findHotKeyForKeyCode:modifierFlags:
@abstract Find an <tt>NDHotKeyEvent</tt>
@ -133,31 +205,76 @@ extern const OSType NDHotKeyDefaultSignature;
@param modifierFlags The modifer flags, ( <tt>NSCommandKeyMask</tt>, <tt>NSControlKeyMask</tt>, <tt>NSAlternateKeyMask</tt>, <tt>NSShiftKeyMask</tt> ).
@result The <tt>NDHotKeyEvent</tt> obejct or nil if none found.
*/
+ (NDHotKeyEvent *)findHotKeyForKeyCode:(unsigned short)keyCode modifierFlags:(unsigned int)modifierFlags;
+ (NDHotKeyEvent *)findHotKeyForKeyCode:(UInt16)keyCode modifierFlags:(NSUInteger)modifierFlags;
/*!
@method hotKeyWithKeyCode:character:modifierFlags:
@method findHotKeyForId:
@abstract Find an <tt>NDHotKeyEvent</tt>
@discussion Finds the <tt>NDHotKeyEvent</tt> for the with the given ID, you can find an already created <tt>NDHotKeyEvent</tt> but there is currently now way to create a new <tt>NDHotKeyEvent</tt> from a HotKey you create with Apple API's.
@param ID The hot key id as returned by <tt>hotKeyId</tt>
@result The <tt>NDHotKeyEvent</tt> obejct or nil if none found.
*/
+ (NDHotKeyEvent *)findHotKeyForId:(UInt32)ID;
/*!
@method hotKeyWithEvent:
@abstract Get a <tt>NDHotKeyEvent</tt> object.
@discussion Returns a new hot key for the supplied event, if there is already a hot key for the supplied key code and modifer flags then nil is returned.
@param event The event generated from the user presssing the desired hot key combination.
@result An new <tt>NDHotKeyEvent</tt> or nil if failure.
*/
+ (id)hotKeyWithEvent:(NSEvent *)event;
/*!
@method hotKeyWithEvent:target:selector:
@abstract Get a <tt>NDHotKeyEvent</tt> object.
@discussion Returns a new hot key for the supplied event, if there is already a hot key for the supplied key code and modifer flags then nil is returned.
@param event The event generated from the user presssing the desired hot key combination.
@param target The target of hot key event.
@param selector The selector sent when hot key is released
@result An new <tt>NDHotKeyEvent</tt> or nil if failure.
*/
+ (id)hotKeyWithEvent:(NSEvent *)event target:(id)target selector:(SEL)selector;
/*!
@method hotKeyWithKeyCharacter:modifierFlags:
@abstract Get a <tt>NDHotKeyEvent</tt> object.
@discussion Returns a new hot key for the supplied hot key combination, if there is already a hot key for the supplied key code and modifer flags then nil is returned.
@param keyCharacter The key character used by the keyboard.
@param modifierFlags The modifer flags, ( <tt>NSCommandKeyMask</tt>, <tt>NSControlKeyMask</tt>, <tt>NSAlternateKeyMask</tt>, <tt>NSShiftKeyMask</tt>, <tt>NSNumericPadKeyMask</tt> ).
@result An new <tt>NDHotKeyEvent</tt> or nil if failure.
*/
+ (id)hotKeyWithKeyCharacter:(unichar)keyCharacter modifierFlags:(NSUInteger)modifer;
/*!
@method hotKeyWithKeyCode:modifierFlags:
@abstract Get a <tt>NDHotKeyEvent</tt> object.
@discussion Returns a new hot key for the supplied hot key combination, if there is already a hot key for the supplied key code and modifer flags then nil is returned.
@param keyCode The key code used by the keyboard, can vary across hardware.
@param aChar The character, used for display purposes only.
@param modifierFlags The modifer flags, ( <tt>NSCommandKeyMask</tt>, <tt>NSControlKeyMask</tt>, <tt>NSAlternateKeyMask</tt>, <tt>NSShiftKeyMask</tt> ).
@result An new <tt>NDHotKeyEvent</tt> or nil if failure.
*/
+ (id)hotKeyWithKeyCode:(unsigned short)keyCode character:(unichar)aChar modifierFlags:(unsigned int)modifer;
+ (id)hotKeyWithKeyCode:(UInt16)keyCode modifierFlags:(NSUInteger)modifer;
/*!
@method hotKeyWithKeyCode:character:modifierFlags:target:selector:
@method hotKeyWithKeyCharacter:modifierFlags:target:selector:
@abstract Get a <tt>NDHotKeyEvent</tt> object.
@discussion Returns a new hot key for the supplied hot key combination and target object and selector, if there is already a hot key for the supplied key code and modifer flags then nil is returned.
@param keyCharacter The key character used by the keyboard.
@param modifierFlags The modifer flags, ( <tt>NSCommandKeyMask</tt>, <tt>NSControlKeyMask</tt>, <tt>NSAlternateKeyMask</tt>, <tt>NSShiftKeyMask</tt>, <tt>NSNumericPadKeyMask</tt> ).
@param target The target of hot key event.
@param selector The selector sent when hot key is released
@result A new <tt>NDHotKeyEvent</tt>
*/
+ (id)hotKeyWithKeyCharacter:(unichar)keyCharacter modifierFlags:(NSUInteger)modifer target:(id)target selector:(SEL)selector;
/*!
@method hotKeyWithKeyCode:modifierFlags:target:selector:
@abstract Get a <tt>NDHotKeyEvent</tt> object.
@discussion Returns a new hot key for the supplied hot key combination and target object and selector, if there is already a hot key for the supplied key code and modifer flags then nil is returned.
@param keyCode The key code used by the keyboard, can vary across hardware.
@param aChar The character, used for display purposes only.
@param modifierFlags The modifer flags, ( <tt>NSCommandKeyMask</tt>, <tt>NSControlKeyMask</tt>, <tt>NSAlternateKeyMask</tt>, <tt>NSShiftKeyMask</tt> ).
@param target The target of hot key event.
@param selector The selector sent when hot key is released
@result A new <tt>NDHotKeyEvent</tt>
*/
+ (id)hotKeyWithKeyCode:(unsigned short)keyCode character:(unichar)aChar modifierFlags:(unsigned int)modifer target:(id)target selector:(SEL)selector;
+ (id)hotKeyWithKeyCode:(UInt16)keyCode modifierFlags:(NSUInteger)modifer target:(id)target selector:(SEL)selector;
/*!
@method initWithPropertyList:
@ -167,29 +284,66 @@ extern const OSType NDHotKeyDefaultSignature;
@result A initialized <tt>NDHotKeyEvent</tt>
*/
+ (id)hotKeyWithWithPropertyList:(id)propertyList;
/*!
@method initWithEvent:
@abstract Initialize a <tt>NDHotKeyEvent</tt> object.
@discussion Initialize the reciever with the supplied hot key combination contained with the event <tt>event</tt> and target object and selector, if there is already a hot key for the supplied event then nil is returned.
@param event The key code used by the keyboard, can vary across hardware.
@result A initialized <tt>NDHotKeyEvent</tt>
*/
- (id)initWithEvent:(NSEvent *)event;
/*!
@method initWithEvent:target:selector:
@abstract Initialize a <tt>NDHotKeyEvent</tt> object.
@discussion Initialize the reciever with the supplied hot key combination contained with the event <tt>event</tt> and target object and selector, if there is already a hot key for the supplied event then nil is returned.
@param event An event used to create a hot key from.
@param target The target of hot key event.
@param selector The selector sent when hot key is released
@result A initialized <tt>NDHotKeyEvent</tt>
*/
- (id)initWithEvent:(NSEvent *)event target:(id)target selector:(SEL)selector;
/*!
@method initWithKeyCode:character:modifierFlags:target:selector:
@abstract Initialize a <tt>NDHotKeyEvent</tt> object.
@discussion Initialize the reciever with the supplied hot key combination and target object and selector, if there is already a hot key for the supplied key code and modifer flags then nil is returned.
@param keyCharacter The key character used by the keyboard.
@param modifierFlags The modifer flags, ( <tt>NSCommandKeyMask</tt>, <tt>NSControlKeyMask</tt>, <tt>NSAlternateKeyMask</tt>, <tt>NSShiftKeyMask</tt>, <tt>NSNumericPadKeyMask</tt>, <tt>NSNumericPadKeyMask</tt> ).
@param target The target of hot key event.
@param selector The selector sent when hot key is released
@result A initialized <tt>NDHotKeyEvent</tt>
*/
- (id)initWithKeyCharacter:(unichar)keyCharacter modifierFlags:(NSUInteger)modifer target:(id)target selector:(SEL)selector;
/*!
@method initWithKeyCode:character:modifierFlags:target:selector:
@abstract Initialize a <tt>NDHotKeyEvent</tt> object.
@discussion Initialize the reciever with the supplied hot key combination and target object and selector, if there is already a hot key for the supplied key code and modifer flags then nil is returned.
@param keyCode The key code used by the keyboard, can vary across hardware.
@param aChar The character, used for display purposes only.
@param modifierFlags The modifer flags, ( <tt>NSCommandKeyMask</tt>, <tt>NSControlKeyMask</tt>, <tt>NSAlternateKeyMask</tt>, <tt>NSShiftKeyMask</tt> ).
@param target The target of hot key event.
@param selector The selector sent when hot key is released
@result A initialized <tt>NDHotKeyEvent</tt>
*/
- (id)initWithKeyCode:(unsigned short)keyCode character:(unichar)aChar modifierFlags:(unsigned int)modifer target:(id)target selector:(SEL)selector;
- (id)initWithKeyCode:(UInt16)keyCode modifierFlags:(NSUInteger)modifer target:(id)target selector:(SEL)selector;
/*!
@method initWithKeyCode:character:modifierFlags
@abstract Initialize a <tt>NDHotKeyEvent</tt> object.
@discussion Initialize the reciever with the supplied hot key combination, if there is already a hot key for the supplied key code and modifer flags then nil is returned.
@param keyCharacter The key character used by the keyboard.
@param modifierFlags The modifer flags, ( <tt>NSCommandKeyMask</tt>, <tt>NSControlKeyMask</tt>, <tt>NSAlternateKeyMask</tt>, <tt>NSShiftKeyMask</tt>, <tt>NSNumericPadKeyMask</tt> ).
@result A initialized <tt>NDHotKeyEvent</tt>
*/
- (id)initWithKeyCharacter:(unichar)keyCharacter modifierFlags:(NSUInteger)modifer;
/*!
@method initWithKeyCode:character:modifierFlags
@abstract Initialize a <tt>NDHotKeyEvent</tt> object.
@discussion Initialize the reciever with the supplied hot key combination, if there is already a hot key for the supplied key code and modifer flags then nil is returned.
@param keyCode The key code used by the keyboard, can vary across hardware.
@param aChar The character, used for display purposes only.
@param modifierFlags The modifer flags, ( <tt>NSCommandKeyMask</tt>, <tt>NSControlKeyMask</tt>, <tt>NSAlternateKeyMask</tt>, <tt>NSShiftKeyMask</tt> ).
@result A initialized <tt>NDHotKeyEvent</tt>
*/
- (id)initWithKeyCode:(unsigned short)keyCode character:(unichar)aChar modifierFlags:(unsigned int)modifer;
- (id)initWithKeyCode:(UInt16)keyCode modifierFlags:(NSUInteger)modifer;
/*!
@method initWithPropertyList:
@ -254,14 +408,14 @@ extern const OSType NDHotKeyDefaultSignature;
*/
- (void)encodeWithCoder:(NSCoder *)encoder;
- (BOOL)setEnabled:(BOOL)flag;
/*!
@method setEnabled:
@method setIsEnabled:
@abstract Set the hot key enabled or disable.
@discussion <tt>setEnabled:</tt> registers or unregisters the recievers hot key combination.
@param flag <tt>YES</tt> to enable, <tt>NO</tt> to disable.
@result Returns <tt>YES</tt> if successful
*/
- (BOOL)setEnabled:(BOOL)flag;
- (void)setIsEnabled:(BOOL)flag;
/*!
@method isEnabled
@ -322,24 +476,45 @@ extern const OSType NDHotKeyDefaultSignature;
/*!
@method setTarget:selector:
@abstract Set the hot key target.
@discussion Set the target object and selector to be sent when the hot key is released.
@param target The traget object.
@discussion Set the target object and selector to be sent when the hot key is released. The target needs to either respond to the method represented by the selector <tt>selector</tt> or to the method <tt>makeObjectsPerformSelector:withObject:</tt> in which case the method <tt>makeObjectsPerformSelector:withObject:</tt> is invoked with the selector <tt>selector</tt>, for example <tt>NSArray</tt>
@param target The traget object or a collection (for example <tt>NSArray</tt>) of target.
@param selector The selector.
@result returns <tt>YES</tt> if successful.
*/
- (BOOL)setTarget:(id)target selector:(SEL)selector;
#ifdef NS_BLOCKS_AVAILABLE
/*!
@method setBlock:
@abstract Set the hot key block called when the hot key is released.
@discussion Sets a block to be executed on hot key release.
@param block The block executed on key release, the block is passed the <tt>NDHotKeyEvent</tt> that represents the event.
@result returns <tt>YES</tt> if successful.
*/
- (BOOL)setBlock:(void(^)(NDHotKeyEvent*))block;
#endif
/*!
@method setTarget:selectorReleased:selectorPressed:
@abstract Set the hot key target.
@discussion Set the target object and selector to be sent when the hot key is pressed and wehn it is released.
@param target The traget object.
@discussion Set the target object and selector to be sent when the hot key is pressed and wehn it is released. The target needs to either respond to the method represented by the selector <tt>selector</tt> or to the method <tt>makeObjectsPerformSelector:withObject:</tt> in which case the method <tt>makeObjectsPerformSelector:withObject:</tt> is invoked with the selector <tt>selector</tt>, for example <tt>NSArray</tt>
@param target The traget object or a collection (for example <tt>NSArray</tt>) of target.
@param selectorReleased The key released selector.
@param selectorPressed The key pressed selector.
@result returns <tt>YES</tt> if successful.
*/
- (BOOL)setTarget:(id)target selectorReleased:(SEL)selectorReleased selectorPressed:(SEL)selectorPressed;
#ifdef NS_BLOCKS_AVAILABLE
/*!
@method setReleasedBlock:pressedBlock:
@abstract Set the hot key blocks called when the hot key is pressed and released.
@discussion Sets blocks to be executed on hot key released and pressed.
@param releasedBlock The block executed on key release, the block is passed the <tt>NDHotKeyEvent</tt> that represents the event.
@param pressedBlock The block executed on key pressed, the block is passed the <tt>NDHotKeyEvent</tt> that represents the event.
@result returns <tt>YES</tt> if successful.
*/
- (BOOL)setReleasedBlock:(void(^)(NDHotKeyEvent*))releasedBlock pressedBlock:(void(^)(NDHotKeyEvent*))pressedBlock;
#endif
/*!
@method performHotKeyReleased
@abstract Invoke the target with the release selector.
@ -360,15 +535,15 @@ extern const OSType NDHotKeyDefaultSignature;
@discussion The key code for the hot key, this is hardware specific.
@result The key code.
*/
- (unsigned short)keyCode;
- (UInt16)keyCode;
/*!
@method character
@method keyCharacter
@abstract Get the hot key character.
@discussion This is the character for the key code, without modifier keys. The character is for display purposes only and dose not determine the key code.
@result A uni code character.
*/
- (unichar)character;
- (unichar)keyCharacter;
/*!
@method modifierFlags
@ -376,7 +551,14 @@ extern const OSType NDHotKeyDefaultSignature;
@discussion The <tt>modifierFlags</tt> can be a bitwise and combination of <tt>NSControlKeyMask</tt>, <tt>NSAlternateKeyMask</tt>, <tt>NSShiftKeyMask</tt>, and <tt>NSCommandKeyMask</tt>.
@result The modifer key flags.
*/
- (unsigned int)modifierFlags;
- (NSUInteger)modifierFlags;
/*!
@method hotKeyId
@abstract Get the hot key id.
@discussion The id is how Apples 'Carbon Event Manager' keeps track of hot keys, if you want to use apples Hot Key function directly with <tt>NDHotKeyEvent</tt> then you can use the value returned from this method.
*/
- (UInt32)hotKeyId;
/*!
@method stringValue
@ -386,6 +568,16 @@ extern const OSType NDHotKeyDefaultSignature;
*/
- (NSString *)stringValue;
/*!
@methodgroup Deprecated Methods
*/
+ (NDHotKeyEvent *)getHotKeyForKeyCode:(UInt16)keyCode character:(unichar)aChar modifierFlags:(NSUInteger)modifierFlags DEPRECATED_ATTRIBUTE;
+ (id)hotKeyWithKeyCode:(UInt16)keyCode character:(unichar)aChar modifierFlags:(NSUInteger)modifer DEPRECATED_ATTRIBUTE;
+ (id)hotKeyWithKeyCode:(UInt16)keyCode character:(unichar)aChar modifierFlags:(NSUInteger)modifer target:(id)target selector:(SEL)selector DEPRECATED_ATTRIBUTE;
- (id)initWithKeyCode:(UInt16)keyCode character:(unichar)aChar modifierFlags:(NSUInteger)modifer target:(id)target selector:(SEL)selector DEPRECATED_ATTRIBUTE;
- (id)initWithKeyCode:(UInt16)keyCode character:(unichar)aChar modifierFlags:(NSUInteger)modifer DEPRECATED_ATTRIBUTE;
@end
/*!
@ -399,29 +591,10 @@ extern const OSType NDHotKeyDefaultSignature;
@method targetWillChangeToObject:forHotKeyEvent:
@abstract Message sent to a target object to inform it that the target is going to change.
@discussion This method can be used to notify the receiver that it will no longer be the target for a <tt>NDHotKeyEvent</tt> or used to prevent the target from changing by returning <tt>NO</tt>
@param target The new target for the <tt>NDHotKeyEvent</tt>
@param target The new target for the <tt>NDHotKeyEvent</tt> or a collection (for example <tt>NSArray</tt>) of target.
@param hotKeyEvent The <tt>NDHotKeyEvent</tt> for which the target is changing.
@result Return <tt>NO</tt> to prevent the target from changing, otherwise return <tt>YES</tt>.
*/
- (BOOL)targetWillChangeToObject:(id)target forHotKeyEvent:(NDHotKeyEvent *)hotKeyEvent;
@end
/*!
@function stringForKeyCodeAndModifierFlags
@abstract Get a string for hot key parameters.
@discussion Returns a string representation of the passed in hot key values.
@param keyCode A key code.
@param aChar A character representation of the key code.
@param modifierFlags modifer flags, comman, option, shift and control.
@result A <tt>NSString</tt> representing the hot key combination.
*/
NSString * stringForKeyCodeAndModifierFlags( unsigned short keyCode, unichar aChar, unsigned int modifierFlags );
/*!
@function unicharForKeyCode
@abstract Get a unicode charater for the key combination.
@discussion The uncode chararter for the key combination.
@param keyCode The key code used by the keyboard, can vary across hardware.
@result A <tt>unichar</tt>
*/
unichar unicharForKeyCode( unsigned short keyCode );

View File

@ -0,0 +1,924 @@
/*
NDHotKeyEvent.m
Created by Nathan Day on 21.06.06 under a MIT-style license.
Copyright (c) 2008 Nathan Day
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#import "NDHotKeyEvent.h"
#import "NDKeyboardLayout.h"
static const NSUInteger kNDHotKeyEventVersion = 2;
@interface NDHotKeyEvent ()
#ifdef NDMapTableClassDefined
+ (NSMapTable *)allHotKeyEvents;
#else
+ (NSHashTable *)allHotKeyEvents;
#endif
- (void)addHotKey;
- (void)removeHotKey;
- (BOOL)setCollectiveEnabled:(BOOL)aFlag;
- (BOOL)collectiveEnable;
@end
static NSString * kArchivingKeyCodeKey = @"KeyCodeKey",
* kArchivingKeyCharacterKey = @"KeyCharacterKey",
* kArchivingModifierFlagsKey = @"ModifierFlagsKey",
* kArchivingSelectorReleasedCodeKey = @"SelectorReleasedCodeKey",
* kArchivingSelectorPressedCodeKey = @"SelectorPressedCodeKey";
const OSType NDHotKeyDefaultSignature = 'NDHK';
static OSStatus switchHotKey( NDHotKeyEvent * self, BOOL aFlag );
@interface NDHotKeyEvent ()
@end
/*
* class implementation NDHotKeyEvent
*/
@implementation NDHotKeyEvent
#ifdef NDHotKeyEventThreadSafe
#warning Thread saftey has been enabled for NDHotKeyEvent class methods
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4
#define NDHotKeyEventLock @synchronized([self class]) {
#define NDHotKeyEventUnlock }
#else
static NSLock * hotKeysLock = nil;
#define NDHotKeyEventLock [hotKeysLock lock]
#define NDHotKeyEventUnlock [hotKeysLock unlock]
#endif
#else
#define NDHotKeyEventLock // lock
#define NDHotKeyEventUnlock // unlock
#endif
#ifdef NDMapTableClassDefined
static NSMapTable * allHotKeyEvents = nil;
#else
static NSHashTable * allHotKeyEvents = NULL;
#endif
static EventHandlerRef hotKeysEventHandler = NULL;
static OSType signature = 0;
static pascal OSErr eventHandlerCallback( EventHandlerCallRef anInHandlerCallRef, EventRef anInEvent, void * self );
#ifndef NDMapTableClassDefined
static NSUInteger hashValueHashFunction( NSHashTable * aTable, const void * aHotKeyEvent );
static BOOL isEqualHashFunction( NSHashTable * aTable, const void * aFirstHotKeyEvent, const void * aSecondHotKeyEvent);
static NSString * describeHashFunction( NSHashTable * aTable, const void * aHotKeyEvent );
#endif
static UInt32 _idForCharacterAndModifer( unichar aCharacter, NSUInteger aModFlags ) { return (NSUInteger)aCharacter | (aModFlags<<16); }
static void _getCharacterAndModiferForId( UInt32 anId, unichar *aCharacter, NSUInteger *aModFlags )
{
*aModFlags = anId>>16;
*aCharacter = anId&0xFFFF;
}
struct HotKeyMappingEntry
{
UInt32 hotKeyId;
NDHotKeyEvent * hotKeyEvent;
};
+ (BOOL)install
{
if( hotKeysEventHandler == NULL )
{
id theHotKeyEvents = [self allHotKeyEvents];
EventTypeSpec theTypeSpec[] =
{
{ kEventClassKeyboard, kEventHotKeyPressed },
{ kEventClassKeyboard, kEventHotKeyReleased }
};
NDHotKeyEventLock;
if( theHotKeyEvents != nil && hotKeysEventHandler == NULL )
{
if( InstallEventHandler( GetEventDispatcherTarget(), NewEventHandlerUPP((EventHandlerProcPtr)eventHandlerCallback), 2, theTypeSpec, theHotKeyEvents, &hotKeysEventHandler ) != noErr )
NSLog(@"Could not install Event handler");
}
NDHotKeyEventUnlock;
}
return hotKeysEventHandler != NULL;
}
+ (void)uninstall
{
if( hotKeysEventHandler != NULL )
RemoveEventHandler( hotKeysEventHandler );
}
+ (void)initialize
{
[NDHotKeyEvent setVersion:kNDHotKeyEventVersion]; // the character attribute has been removed
#ifdef NDHotKeyEventThreadSafe
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_4
if( hotKeysLock == nil )
{
NSLock * theInstance = [[NSLock alloc] init];
if( !CompareAndSwap( nil, (unsigned long int)theInstance, (unsigned long int*)&hotKeysLock) )
[theInstance release]; // did not use instance
}
#endif
#endif
}
+ (void)setSignature:(OSType)aSignature
{
NSAssert( signature == 0 || aSignature == signature, @"The signature used by NDHotKeyEvent can only be set once safely" );
signature = aSignature;
}
+ (OSType)signature
{
signature = signature ? signature : NDHotKeyDefaultSignature;
return signature;
}
+ (BOOL)setAllEnabled:(BOOL)aFlag
{
BOOL theAllSucceeded = YES;
#ifdef NDMapTableClassDefined
NSMapTable * theAllHotKeyEvents = [NDHotKeyEvent allHotKeyEvents];
#else
NSHashTable * theAllHotKeyEvents = [NDHotKeyEvent allHotKeyEvents];
#endif
/*
* need to install before to make sure the method 'setCollectiveEnabled:'
* doesn't try install since install tries to aquire the lock 'hotKeysLock'
*/
if( theAllHotKeyEvents && [NDHotKeyEvent install] )
{
#ifdef NDMapTableClassDefined
NDHotKeyEventLock;
for( NDHotKeyEvent * theHotEvent in [theAllHotKeyEvents objectEnumerator] )
{
if( ![theHotEvent setCollectiveEnabled:aFlag] )
theAllSucceeded = NO;
}
NDHotKeyEventUnlock;
#else
NSHashEnumerator theEnumerator;
struct HotKeyMappingEntry * theHotKeyMapEntry;
NDHotKeyEventLock;
theEnumerator = NSEnumerateHashTable( theAllHotKeyEvents );
while( (theHotKeyMapEntry = (struct HotKeyMappingEntry*)NSNextHashEnumeratorItem(&theEnumerator) ) )
{
if( ![theHotKeyMapEntry->hotKeyEvent setCollectiveEnabled:aFlag] )
theAllSucceeded = NO;
}
NSEndHashTableEnumeration( &theEnumerator );
NDHotKeyEventUnlock;
#endif
}
return theAllSucceeded;
}
+ (BOOL)isEnabledKeyCharacter:(unichar)aKeyCharacter modifierFlags:(NSUInteger)aModifierFlags
{
return [[self findHotKeyForKeyCode:[[NDKeyboardLayout keyboardLayout] keyCodeForCharacter:aKeyCharacter numericPad:(aModifierFlags&NSNumericPadKeyMask) != 0] modifierFlags:aModifierFlags] isEnabled];
}
+ (BOOL)isEnabledKeyCode:(UInt16)aKeyCode modifierFlags:(NSUInteger)aModifierFlags
{
return [[self findHotKeyForKeyCode:aKeyCode modifierFlags:aModifierFlags] isEnabled];
}
+ (NDHotKeyEvent *)getHotKeyForKeyCode:(UInt16)aKeyCode modifierFlags:(NSUInteger)aModifierFlags
{
return [self getHotKeyForKeyCharacter:[[NDKeyboardLayout keyboardLayout] characterForKeyCode:aKeyCode] modifierFlags:aModifierFlags];
}
#pragma mark - finding hot key event objects
+ (NDHotKeyEvent *)getHotKeyForKeyCharacter:(unichar)aKeyCharacter modifierFlags:(NSUInteger)aModifierFlags
{
NDHotKeyEvent * theHotKey = nil;
theHotKey = [self findHotKeyForKeyCharacter:aKeyCharacter modifierFlags:aModifierFlags];
return theHotKey ? theHotKey : [self hotKeyWithKeyCharacter:aKeyCharacter modifierFlags:aModifierFlags];
}
+ (NDHotKeyEvent *)findHotKeyForKeyCode:(UInt16)aKeyCode modifierFlags:(NSUInteger)aModifierFlags
{
return [self findHotKeyForKeyCharacter:[[NDKeyboardLayout keyboardLayout] characterForKeyCode:aKeyCode] modifierFlags:aModifierFlags];
}
+ (NDHotKeyEvent *)findHotKeyForKeyCharacter:(unichar)aKeyCharacter modifierFlags:(NSUInteger)aModifierFlags
{
return [self findHotKeyForId:_idForCharacterAndModifer(aKeyCharacter, aModifierFlags)];
}
+ (NDHotKeyEvent *)findHotKeyForId:(UInt32)anID
{
NDHotKeyEvent * theResult = nil;
#ifdef NDMapTableClassDefined
NSMapTable * theAllHotKeyEvents = [NDHotKeyEvent allHotKeyEvents];
#else
NSHashTable * theAllHotKeyEvents = [NDHotKeyEvent allHotKeyEvents];
#endif
if( theAllHotKeyEvents )
{
#ifdef NDMapTableClassDefined
NDHotKeyEventLock;
theResult = [theAllHotKeyEvents objectForKey:[NSNumber numberWithUnsignedInt:anID]];
NDHotKeyEventUnlock;
#else
struct HotKeyMappingEntry * theFoundEntry = NULL;
struct HotKeyMappingEntry theDummyEntry = {anID,nil};
NDHotKeyEventLock;
theFoundEntry = NSHashGet( theAllHotKeyEvents, (void*)&theDummyEntry);
if( theFoundEntry != NULL )
[[theFoundEntry->hotKeyEvent retain] autorelease];
NDHotKeyEventUnlock;
theResult = (theFoundEntry) ? theFoundEntry->hotKeyEvent : nil;
#endif
}
return theResult;
}
+ (id)hotKeyWithEvent:(NSEvent *)anEvent
{
return [[[self alloc] initWithEvent:anEvent] autorelease];
}
+ (id)hotKeyWithEvent:(NSEvent *)anEvent target:(id)aTarget selector:(SEL)aSelector
{
return [[[self alloc] initWithEvent:anEvent target:aTarget selector:aSelector] autorelease];
}
+ (id)hotKeyWithKeyCharacter:(unichar)aKeyCharacter modifierFlags:(NSUInteger)aModifierFlags
{
return [[[self alloc] initWithKeyCharacter:aKeyCharacter modifierFlags:aModifierFlags target:nil selector:(SEL)0] autorelease];
}
+ (id)hotKeyWithKeyCode:(UInt16)aKeyCode modifierFlags:(NSUInteger)aModifierFlags
{
return [[[self alloc] initWithKeyCode:aKeyCode modifierFlags:aModifierFlags target:nil selector:(SEL)0] autorelease];
}
+ (id)hotKeyWithKeyCharacter:(unichar)aKeyCharacter modifierFlags:(NSUInteger)aModifierFlags target:(id)aTarget selector:(SEL)aSelector
{
return [[[self alloc] initWithKeyCharacter:aKeyCharacter modifierFlags:aModifierFlags target:aTarget selector:aSelector] autorelease];
}
+ (id)hotKeyWithKeyCode:(UInt16)aKeyCode modifierFlags:(NSUInteger)aModifierFlags target:(id)aTarget selector:(SEL)aSelector
{
return [[[self alloc] initWithKeyCode:aKeyCode modifierFlags:aModifierFlags target:aTarget selector:aSelector] autorelease];
}
+ (id)hotKeyWithWithPropertyList:(id)aPropertyList
{
return [[[self alloc] initWithPropertyList:aPropertyList] autorelease];
}
+ (NSString *)description
{
#ifdef NDMapTableClassDefined
NSMapTable * theAllHotKeyEvents = [NDHotKeyEvent allHotKeyEvents];
#else
NSHashTable * theAllHotKeyEvents = [NDHotKeyEvent allHotKeyEvents];
#endif
NSString * theDescription = nil;
if( theAllHotKeyEvents )
{
NDHotKeyEventLock;
#ifdef NDMapTableClassDefined
theDescription = [theAllHotKeyEvents description];
#else
theDescription = NSStringFromHashTable(theAllHotKeyEvents);
#endif
NDHotKeyEventUnlock;
}
return theDescription;
}
#pragma mark - creation and destruction
- (id)init
{
[self release];
NSAssert( NO, @"You can not initialize a Hot Key with the init method" );
return nil;
}
- (id)initWithEvent:(NSEvent *)anEvent
{
return [self initWithEvent:anEvent target:nil selector:NULL];
}
- (id)initWithEvent:(NSEvent *)anEvent target:(id)aTarget selector:(SEL)aSelector
{
unsigned long theModifierFlags = [anEvent modifierFlags] & (NSShiftKeyMask|NSControlKeyMask|NSAlternateKeyMask|NSCommandKeyMask);
return [self initWithKeyCode:[anEvent keyCode]
modifierFlags:theModifierFlags
target:aTarget
selector:aSelector];
}
- (id)initWithKeyCharacter:(unichar)aKeyCharacter modifierFlags:(NSUInteger)aModifierFlags
{
return [self initWithKeyCode:[[NDKeyboardLayout keyboardLayout] keyCodeForCharacter:aKeyCharacter numericPad:(aModifierFlags&NSNumericPadKeyMask) != 0] modifierFlags:aModifierFlags target:nil selector:NULL];
}
- (id)initWithKeyCode:(UInt16)aKeyCode modifierFlags:(NSUInteger)aModifierFlags
{
return [self initWithKeyCode:aKeyCode modifierFlags:aModifierFlags target:nil selector:NULL];
}
- (id)initWithKeyCode:(UInt16)aKeyCode modifierFlags:(NSUInteger)aModifierFlags target:(id)aTarget selector:(SEL)aSelector
{
return [self initWithKeyCharacter:[[NDKeyboardLayout keyboardLayout] characterForKeyCode:aKeyCode] modifierFlags:aModifierFlags target:aTarget selector:aSelector];
}
- (id)initWithKeyCharacter:(unichar)aKeyCharacter modifierFlags:(NSUInteger)aModifierFlags target:(id)aTarget selector:(SEL)aSelector
{
if( (self = [super init]) != nil )
{
keyCharacter = aKeyCharacter;
modifierFlags = aModifierFlags;
target = aTarget;
selectorReleased = aSelector;
currentEventType = NDHotKeyNoEvent;
isEnabled.collective = YES;
[self addHotKey];
}
else
[self release], self = nil;
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
if( (self = [super init]) != nil)
{
if( [aDecoder allowsKeyedCoding] )
{
NSNumber * theValue = [aDecoder decodeObjectForKey:kArchivingKeyCharacterKey];
if( theValue == nil )
{
theValue = [aDecoder decodeObjectForKey:kArchivingKeyCodeKey];
keyCharacter = [[NDKeyboardLayout keyboardLayout] characterForKeyCode:[theValue unsignedShortValue]];
}
else
keyCharacter = [theValue unsignedShortValue];
modifierFlags = [[aDecoder decodeObjectForKey:kArchivingModifierFlagsKey] unsignedIntegerValue];
selectorReleased = NSSelectorFromString( [aDecoder decodeObjectForKey:kArchivingSelectorReleasedCodeKey] );
selectorPressed = NSSelectorFromString( [aDecoder decodeObjectForKey:kArchivingSelectorPressedCodeKey] );
}
else
{
if( [aDecoder versionForClassName:@"NDHotKeyNoEvent"] == 1 )
{
unsigned short theKeyCode;
[aDecoder decodeValueOfObjCType:@encode(UInt16) at:&theKeyCode];
keyCharacter = [[NDKeyboardLayout keyboardLayout] characterForKeyCode:theKeyCode];
}
else
[aDecoder decodeValueOfObjCType:@encode(unichar) at:&keyCharacter];
[aDecoder decodeValueOfObjCType:@encode(NSUInteger) at:&modifierFlags];
selectorReleased = NSSelectorFromString( [aDecoder decodeObject] );
selectorPressed = NSSelectorFromString( [aDecoder decodeObject] );
}
[self addHotKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)anEncoder
{
if( [anEncoder allowsKeyedCoding] )
{
[anEncoder encodeObject:[NSNumber numberWithUnsignedShort:keyCharacter] forKey:kArchivingKeyCharacterKey];
[anEncoder encodeObject:[NSNumber numberWithUnsignedInteger:modifierFlags] forKey:kArchivingModifierFlagsKey];
[anEncoder encodeObject:NSStringFromSelector( selectorReleased ) forKey:kArchivingSelectorReleasedCodeKey];
[anEncoder encodeObject:NSStringFromSelector( selectorPressed ) forKey:kArchivingSelectorPressedCodeKey];
}
else
{
[anEncoder encodeValueOfObjCType:@encode(unichar) at:&keyCharacter];
[anEncoder encodeValueOfObjCType:@encode(NSUInteger) at:&modifierFlags];
[anEncoder encodeObject:NSStringFromSelector( selectorReleased )];
[anEncoder encodeObject:NSStringFromSelector( selectorPressed )];
}
}
- (id)initWithPropertyList:(id)aPropertyList
{
if( aPropertyList )
{
NSNumber * theKeyCode,
* theModiferFlag;
theKeyCode = [aPropertyList objectForKey:kArchivingKeyCodeKey];
theModiferFlag = [aPropertyList objectForKey:kArchivingModifierFlagsKey];
if( (self = [self initWithKeyCode:[theKeyCode unsignedShortValue] modifierFlags:[theModiferFlag unsignedIntValue]]) != nil )
{
selectorPressed = NSSelectorFromString([aPropertyList objectForKey:kArchivingSelectorPressedCodeKey]);
selectorReleased = NSSelectorFromString([aPropertyList objectForKey:kArchivingSelectorReleasedCodeKey]);
}
}
else
[self release], self = nil;
return self;
}
- (id)propertyList
{
return [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithUnsignedShort:[self keyCode]], kArchivingKeyCodeKey,
[NSNumber numberWithUnsignedInt:[self modifierFlags]], kArchivingModifierFlagsKey,
NSStringFromSelector( selectorPressed ), kArchivingSelectorPressedCodeKey,
NSStringFromSelector( selectorReleased ), kArchivingSelectorReleasedCodeKey,
nil];
}
- (oneway void)release
{
/*
* We need to remove the hot key from the hash table before it's retain count reaches zero
*/
if( [self retainCount] == 1 )
{
#ifdef NDMapTableClassDefined
NSMapTable * theAllHotKeyEvents = [NDHotKeyEvent allHotKeyEvents];
#else
NSHashTable * theAllHotKeyEvents = [NDHotKeyEvent allHotKeyEvents];
#endif
if( theAllHotKeyEvents )
{
#ifndef NDMapTableClassDefined
struct HotKeyMappingEntry theDummyEntry = {[self hotKeyId],nil};
#endif
NDHotKeyEventLock;
if( [self retainCount] == 1 ) // check again because it might have changed
{
switchHotKey( self, NO );
#ifdef NDMapTableClassDefined
[theAllHotKeyEvents removeObjectForKey:[NSNumber numberWithUnsignedInt:[self hotKeyId]]];
#else
id theHotKeyEvent = NSHashGet( theAllHotKeyEvents, (void*)&theDummyEntry );
if( theHotKeyEvent )
NSHashRemove( theAllHotKeyEvents, theHotKeyEvent );
#endif
}
NDHotKeyEventUnlock;
}
}
[super release];
}
#if 0
- (void)dealloc
{
if( reference )
{
if( UnregisterEventHotKey( reference ) != noErr ) // in lock from release
NSLog( @"Failed to unregister hot key %@", self );
}
[super dealloc];
}
#endif
- (BOOL)setEnabled:(BOOL)aFlag
{
BOOL theResult = YES;
if( [NDHotKeyEvent install] )
{
/*
* if individual and collective YES then currently ON, otherwise currently off
*/
NDHotKeyEventLock;
if( aFlag == YES && isEnabled.collective == YES && isEnabled.individual == NO )
theResult = (switchHotKey( self, YES ) == noErr);
else if( aFlag == NO && isEnabled.collective == YES && isEnabled.individual == YES )
theResult = (switchHotKey( self, NO ) == noErr);
NDHotKeyEventUnlock;
if( theResult )
isEnabled.individual = aFlag;
else
NSLog(@"%s failed ", aFlag ? "enable" : "disable" );
}
else
theResult = NO;
return theResult;
}
- (void)setIsEnabled:(BOOL)aFlag { [self setEnabled:aFlag]; }
- (BOOL)isEnabled { return isEnabled.individual && isEnabled.collective; }
- (id)target { return target; }
- (SEL)selector { return selectorReleased; }
- (SEL)selectorReleased { return selectorReleased; }
- (SEL)selectorPressed { return selectorPressed; }
- (int)currentEventType { return currentEventType; } // (NDHotKeyNoEvent | NDHotKeyPressedEvent | NDHotKeyReleasedEvent)
- (BOOL)setTarget:(id)aTarget selector:(SEL)aSelector { return [self setTarget:aTarget selectorReleased:aSelector selectorPressed:(SEL)0]; }
#ifdef NS_BLOCKS_AVAILABLE
- (BOOL)setBlock:(void(^)(NDHotKeyEvent*))aBlock { return [self setReleasedBlock:aBlock pressedBlock:nil]; }
#endif
- (BOOL)setTarget:(id)aTarget selectorReleased:(SEL)aSelectorReleased selectorPressed:(SEL)aSelectorPressed
{
BOOL theResult = NO;
[self setEnabled:NO];
if( target != nil && target != aTarget )
{
if( ![target respondsToSelector:@selector(targetWillChangeToObject:forHotKeyEvent:)] || [target targetWillChangeToObject:aTarget forHotKeyEvent:self] )
{
target = aTarget;
theResult = YES;
}
}
else
{
target = aTarget;
theResult = YES;
}
selectorReleased = aSelectorReleased;
selectorPressed = aSelectorPressed;
#ifdef NS_BLOCKS_AVAILABLE
[releasedBlock release], releasedBlock = nil;
[pressedBlock release], pressedBlock = nil;
#endif
return theResult; // was change succesful
}
#ifdef NS_BLOCKS_AVAILABLE
- (BOOL)setReleasedBlock:(void(^)(NDHotKeyEvent*))aReleasedBlock pressedBlock:(void(^)(NDHotKeyEvent*))aPressedBlock
{
BOOL theResult = NO;
[self setEnabled:NO];
if( ![target respondsToSelector:@selector(targetWillChangeToObject:forHotKeyEvent:)] || [target targetWillChangeToObject:nil forHotKeyEvent:self] )
{
if( releasedBlock != aReleasedBlock )
[releasedBlock release], releasedBlock = [aReleasedBlock copy];
if( pressedBlock != aPressedBlock )
[pressedBlock release], pressedBlock = [aPressedBlock copy];
selectorReleased = (SEL)0;
selectorPressed = (SEL)0;
theResult = YES;
}
return theResult; // was change succesful
}
#endif
- (void)performHotKeyReleased
{
NSAssert( target != nil || releasedBlock != nil, @"Release hot key fired without target or release block" );
currentEventType = NDHotKeyReleasedEvent;
if( selectorReleased )
{
if([target respondsToSelector:selectorReleased])
[target performSelector:selectorReleased withObject:self];
else if( [target respondsToSelector:@selector(makeObjectsPerformSelector:withObject:)] )
[target makeObjectsPerformSelector:selectorReleased withObject:self];
}
#ifdef NS_BLOCKS_AVAILABLE
else if( releasedBlock )
releasedBlock(self);
#endif
currentEventType = NDHotKeyNoEvent;
}
- (void)performHotKeyPressed
{
NSAssert( target != nil || pressedBlock != nil, @"Release hot key fired without target or pressed block" );
currentEventType = NDHotKeyPressedEvent;
if( selectorPressed )
{
if([target respondsToSelector:selectorPressed])
[target performSelector:selectorPressed withObject:self];
else if( [target respondsToSelector:@selector(makeObjectsPerformSelector:withObject:)] )
[target makeObjectsPerformSelector:selectorPressed withObject:self];
}
#ifdef NS_BLOCKS_AVAILABLE
else if( pressedBlock )
pressedBlock(self);
#endif
currentEventType = NDHotKeyNoEvent;
}
- (unichar)keyCharacter { return keyCharacter; }
- (BOOL)keyPad { return keyPad; }
- (UInt16)keyCode { return [[NDKeyboardLayout keyboardLayout] keyCodeForCharacter:self.keyCharacter numericPad:self.keyPad]; }
- (NSUInteger)modifierFlags { return modifierFlags; }
- (UInt32)hotKeyId { return _idForCharacterAndModifer( self.keyCharacter, self.modifierFlags ); }
- (NSString *)stringValue { return [[NDKeyboardLayout keyboardLayout] stringForKeyCode:[self keyCode] modifierFlags:[self modifierFlags]]; }
- (BOOL)isEqual:(id)anObject
{
return [super isEqual:anObject] || ([anObject isKindOfClass:[self class]] == YES && [self keyCode] == [(NDHotKeyEvent*)anObject keyCode] && [self modifierFlags] == [anObject modifierFlags]);
}
- (NSUInteger)hash { return (NSUInteger)self.keyCharacter | (self.modifierFlags<<16); }
- (NSString *)description
{
return [NSString stringWithFormat:@"{\n\tKey Combination: %@,\n\tEnabled: %s\n\tKey Press Selector: %@\n\tKey Release Selector: %@\n}\n",
[self stringValue],
[self isEnabled] ? "yes" : "no",
NSStringFromSelector([self selectorPressed]),
NSStringFromSelector([self selectorReleased])];
}
pascal OSErr eventHandlerCallback( EventHandlerCallRef anInHandlerCallRef, EventRef anInEvent, void * anInUserData )
{
// NSHashTable * allHotKeyEvents = (NSHashTable *)anInUserData;
EventHotKeyID theHotKeyID;
OSStatus theError;
NSCAssert( GetEventClass( anInEvent ) == kEventClassKeyboard, @"Got event that is not a hot key event" );
theError = GetEventParameter( anInEvent, kEventParamDirectObject, typeEventHotKeyID, NULL, sizeof(EventHotKeyID), NULL, &theHotKeyID );
if( theError == noErr )
{
NDHotKeyEvent * theHotKeyEvent;
UInt32 theEventKind;
NSCAssert( [NDHotKeyEvent signature] == theHotKeyID.signature, @"Got hot key event with wrong signature" );
theHotKeyEvent = [NDHotKeyEvent findHotKeyForId:theHotKeyID.id];
theEventKind = GetEventKind( anInEvent );
if( kEventHotKeyPressed == theEventKind )
[theHotKeyEvent performHotKeyPressed];
else if( kEventHotKeyReleased == theEventKind )
[theHotKeyEvent performHotKeyReleased];
}
return theError;
}
#ifndef NDMapTableClassDefined
NSUInteger hashValueHashFunction( NSHashTable * aTable, const void * aHotKeyEntry )
{
struct HotKeyMappingEntry * theHotKeyEntry = (struct HotKeyMappingEntry*)aHotKeyEntry;
return theHotKeyEntry->hotKeyId;
}
BOOL isEqualHashFunction( NSHashTable * aTable, const void * aFirstHotKeyEntry, const void * aSecondHotKeyEntry)
{
struct HotKeyMappingEntry * theFirst = (struct HotKeyMappingEntry*)aFirstHotKeyEntry,
* theSecond = (struct HotKeyMappingEntry*)aSecondHotKeyEntry;
return theFirst->hotKeyId == theSecond->hotKeyId;
}
NSString * describeHashFunction( NSHashTable * aTable, const void * aHotKeyEntry )
{
NDHotKeyEvent * theHotKey;
theHotKey = ((struct HotKeyMappingEntry*)aHotKeyEntry)->hotKeyEvent;
return [theHotKey description];
}
#endif
#pragma mark Private methods
#ifdef NDMapTableClassDefined
+ (NSMapTable *)allHotKeyEvents
{
if( allHotKeyEvents == NULL )
{
NDHotKeyEventLock;
if( allHotKeyEvents == NULL )
allHotKeyEvents = [[NSMapTable alloc] initWithKeyOptions:NSMapTableStrongMemory valueOptions:NSMapTableZeroingWeakMemory capacity:0];
NDHotKeyEventUnlock;
}
return allHotKeyEvents;
}
#else
+ (NSHashTable *)allHotKeyEvents
{
if( allHotKeyEvents == NULL )
{
NSHashTableCallBacks theHashCallBacks;
theHashCallBacks.hash = hashValueHashFunction;
theHashCallBacks.isEqual = isEqualHashFunction;
theHashCallBacks.retain = NULL;
theHashCallBacks.release = NULL;
theHashCallBacks.describe = describeHashFunction;
NDHotKeyEventLock;
if( allHotKeyEvents == NULL )
allHotKeyEvents = NSCreateHashTableWithZone( theHashCallBacks, 0, NULL);
NDHotKeyEventUnlock;
}
return allHotKeyEvents;
}
#endif
- (void)addHotKey
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardLayoutSelectedKeyboardInputSourceChangedNotification:) name:NDKeyboardLayoutSelectedKeyboardInputSourceChangedNotification object:nil];
#ifdef NDMapTableClassDefined
NSMapTable * theAllHotKeyEvents = [NDHotKeyEvent allHotKeyEvents];
#else
NSHashTable * theAllHotKeyEvents = [NDHotKeyEvent allHotKeyEvents];
#endif
if( theAllHotKeyEvents )
{
NDHotKeyEventLock;
#ifdef NDMapTableClassDefined
[theAllHotKeyEvents setObject:self forKey:[NSNumber numberWithUnsignedInt:[self hotKeyId]]];
#else
struct HotKeyMappingEntry * theEntry = (struct HotKeyMappingEntry *)malloc(sizeof(struct HotKeyMappingEntry));
theEntry->hotKeyId = [self hotKeyId];
theEntry->hotKeyEvent = self;
NSParameterAssert( NSHashInsertIfAbsent( theAllHotKeyEvents, (void*)theEntry ) == NULL );
#endif
NDHotKeyEventUnlock;
}
}
- (void)keyboardLayoutSelectedKeyboardInputSourceChangedNotification:(NSNotification*)aNotification
{
if( self.isEnabled ) // if enable re-eable using new keyCode
switchHotKey( self, YES );
}
- (void)removeHotKey
{
[self setEnabled:NO];
#ifdef NDMapTableClassDefined
NSMapTable * theAllHotKeyEvents = [NDHotKeyEvent allHotKeyEvents];
#else
NSHashTable * theAllHotKeyEvents = [NDHotKeyEvent allHotKeyEvents];
#endif
if( theAllHotKeyEvents )
{
#ifndef NDMapTableClassDefined
struct HotKeyMappingEntry theDummyEntry = {[self hotKeyId],nil};
struct HotKeyMappingEntry * theEntry = NULL;
#endif
NDHotKeyEventLock;
#ifdef NDMapTableClassDefined
[theAllHotKeyEvents removeObjectForKey:[NSNumber numberWithUnsignedInt:[self hotKeyId]]];
#else
theEntry = (struct HotKeyMappingEntry*)NSHashGet( theAllHotKeyEvents, (void*)&theDummyEntry);
if( theEntry )
{
NSParameterAssert( theEntry->hotKeyEvent == self );
NSHashRemove( theAllHotKeyEvents, theEntry );
}
#endif
NDHotKeyEventUnlock;
}
}
- (BOOL)setCollectiveEnabled:(BOOL)aFlag
{
BOOL theResult = YES;
if( [NDHotKeyEvent install] )
{
/*
* if individual and collective YES then currently ON, otherwise currently off
*/
NDHotKeyEventLock;
if( aFlag == YES && isEnabled.collective == NO && isEnabled.individual == YES )
theResult = (switchHotKey( self, YES ) == noErr);
else if( aFlag == NO && isEnabled.collective == YES && isEnabled.individual == YES )
theResult = (switchHotKey( self, NO ) == noErr);
NDHotKeyEventUnlock;
if( theResult )
isEnabled.collective = aFlag;
else
NSLog(@"%s failed", aFlag ? "enable" : "disable" );
}
else
theResult = NO;
return theResult;
}
- (BOOL)collectiveEnable { return isEnabled.collective; }
static OSStatus switchHotKey( NDHotKeyEvent * self, BOOL aFlag )
{
OSStatus theError = noErr;
if( aFlag )
{
EventHotKeyID theHotKeyID;
if( self->reference )
theError = UnregisterEventHotKey( self->reference );
if( theError == noErr )
{
theHotKeyID.signature = [NDHotKeyEvent signature];
theHotKeyID.id = [self hotKeyId];
NSCAssert( theHotKeyID.signature, @"HotKeyEvent signature has not been set yet" );
NSCParameterAssert(sizeof(unsigned long) >= sizeof(id) );
theError = RegisterEventHotKey( self.keyCode, NDCarbonModifierFlagsForCocoaModifierFlags(self->modifierFlags), theHotKeyID, GetEventDispatcherTarget(), 0, &self->reference );
}
}
else
{
theError = UnregisterEventHotKey( self->reference );
self->reference = 0;
}
return theError;
}
#pragma mark - Deprecated Methods
+ (NDHotKeyEvent *)getHotKeyForKeyCode:(UInt16)aKeyCode character:(unichar)aChar modifierFlags:(NSUInteger)aModifierFlags
{
return [self getHotKeyForKeyCode:aKeyCode modifierFlags:aModifierFlags];
}
/*
* +hotKeyWithKeyCode:character:modifierFlags:
*/
+ (id)hotKeyWithKeyCode:(UInt16)aKeyCode character:(unichar)aChar modifierFlags:(NSUInteger)aModifierFlags
{
return [self hotKeyWithKeyCode:aKeyCode modifierFlags:aModifierFlags target:nil selector:NULL];
}
/*
* +hotKeyWithKeyCode:character:modifierFlags:target:selector:
*/
+ (id)hotKeyWithKeyCode:(UInt16)aKeyCode character:(unichar)aChar modifierFlags:(NSUInteger)aModifierFlags target:(id)aTarget selector:(SEL)aSelector
{
return [[[self alloc] initWithKeyCode:aKeyCode modifierFlags:aModifierFlags target:aTarget selector:aSelector] autorelease];
}
/*
* -initWithKeyCode:character:modifierFlags:
*/
- (id)initWithKeyCode:(UInt16)aKeyCode character:(unichar)aChar modifierFlags:(NSUInteger)aModifierFlags
{
return [self initWithKeyCode:aKeyCode modifierFlags:aModifierFlags target:nil selector:NULL];
}
/*
* -initWithKeyCode:character:modifierFlags:target:selector:
*/
- (id)initWithKeyCode:(UInt16)aKeyCode character:(unichar)aChar modifierFlags:(NSUInteger)aModifierFlags target:(id)aTarget selector:(SEL)aSelector
{
return [self initWithKeyCode:aKeyCode modifierFlags:aModifierFlags target:aTarget selector:aSelector];
}
@end

View File

@ -0,0 +1,135 @@
/*
NDKeyboardLayout.h
Created by Nathan Day on 01.18.10 under a MIT-style license.
Copyright (c) 2010 Nathan Day
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/*!
@header NDKeyboardLayout.h
@abstract Header file for NDKeyboardLayout
@author Nathan Day
*/
#import <Cocoa/Cocoa.h>
#import <CoreServices/CoreServices.h>
#import <Carbon/Carbon.h>
struct ReverseMappingEntry;
extern NSString * const NDKeyboardLayoutSelectedKeyboardInputSourceChangedNotification;
extern NSString * const NDKeyboardLayoutPreviousKeyboardLayoutUserInfoKey;
/*!
@function NDCocoaModifierFlagsForCarbonModifierFlags
Convert Carbon modifer flags to Cocoa modifier flags.
@param modifierFlags one or more of the flags <tt>shiftKey</tt>, <tt>controlKey</tt>, <tt>optionKey</tt>, <tt>cmdKey</tt>
*/
NSUInteger NDCocoaModifierFlagsForCarbonModifierFlags( NSUInteger modifierFlags );
/*!
@function NDCarbonModifierFlagsForCocoaModifierFlags
Convert Cocoa modifer flags to Carbon modifier flags.
@param modifierFlags one or more of the flags <tt>NSShiftKeyMask</tt>, <tt>NSControlKeyMask</tt>, <tt>NSAlternateKeyMask</tt>, <tt>NSCommandKeyMask</tt>
*/
NSUInteger NDCarbonModifierFlagsForCocoaModifierFlags( NSUInteger modifierFlags );
/*!
@class NDKeyboardLayout
@abstract Class for translating between key codes and key characters.
@discussion The key code for each key character can change between hardware and with localisation, <tt>NDKeyboardLayout</tt> handles translation between key codes and key characters as well as for generating strings for display purposes.
@helps Used by <tt>NDHotKeyEvent</tt>.
*/
@interface NDKeyboardLayout : NSObject
{
@private
CFDataRef keyboardLayoutData;
struct ReverseMappingEntry * mappings;
NSUInteger numberOfMappings;
}
/*!
@method keyboardLayout
Get a keyboard layout for the current keyboard
*/
+ (id)keyboardLayout;
/*!
@method init
initialise a keyboard layout for the current keyboard, if that fails a keyboard layout for one of the languages
returned from <tt>[NSLocale preferredLanguages]</tt> is attempted and if finally if that fails a keyboard layout
for the most recently used ASCII-capable keyboard is created. If that fails then this method returns <tt>nil</tt>.
*/
- (id)init;
/*!
@method initWithLanguage:
@abstract initialise a keyboard layout.
@discussion Initialises a KeyboardLayout with an <tt>TISInputSourceRef</tt> for the supplied language.
*/
- (id)initWithLanguage:(NSString *)langauge;
/*!
@method initWithInputSource:
@abstract initialise a keyboard layout.
@discussion Initialises a KeyboardLayout with an <tt>TISInputSourceRef</tt>, this method is called with the result from <tt>initWithInputSource:TISCopyCurrentKeyboardInputSource()</tt>.
*/
- (id)initWithInputSource:(TISInputSourceRef)source;
/*!
@method stringForCharacter:modifierFlags:
@abstract Get a string for display purposes.
@discussion <tt>stringForCharacter:modifierFlags:</tt> returns a string that can be displayed to the user, For example command-z would produce &#x2318;Z, shift-T would produce &#x21E7;T.
@param character The unmodified character on the keyboard.
@param modifierFlags Modifier flags <tt>NSControlKeyMask</tt>, <tt>NSAlternateKeyMask</tt>, <tt>NSShiftKeyMask</tt>, <tt>NSCommandKeyMask</tt> and <tt>NSNumericPadKeyMask</tt>.
*/
- (NSString*)stringForCharacter:(unichar)character modifierFlags:(UInt32)modifierFlags;
/*!
@method stringForKeyCode:modifierFlags:
@abstract Get a string for display purposes.
@discussion <tt>stringForKeyCode:modifierFlags:</tt> returns a string that can be displayed to the user. This method is called by <tt>stringForCharacter::modifierFlags</tt> and is problem more useful most of the time.
@param keyCode A value specifying the virtual key code that is to be translated. For ADB keyboards, virtual key codes are in the range from 0 to 127.
@param modifierFlags Modifier flags <tt>NSControlKeyMask</tt>, <tt>NSAlternateKeyMask</tt>, <tt>NSShiftKeyMask</tt>, <tt>NSCommandKeyMask</tt> and <tt>NSNumericPadKeyMask</tt>.
*/
- (NSString*)stringForKeyCode:(UInt16)keyCode modifierFlags:(UInt32)modifierFlags;
/*!
@method characterForKeyCode:
@abstract Get the key character for a given key code.
@discussion The character returned is the unmodified version on the keyboard.
@param keyCode A value specifying the virtual key code that is to be translated. For ADB keyboards, virtual key codes are in the range from 0 to 127.
@result The character for the unmodified version of the key.
*/
- (unichar)characterForKeyCode:(UInt16)keyCode;
/*!
@method keyCodeForCharacter:numericPad:
@abstract Get the key code for a given key character.
@discussion The character pass in must be the unshifter character for the key, for example to get the key code for the '?' on keyboards where you type shift-/ to get '?' you should pass in the character '/"
@param character The unmodified character on the keyboard.
@param numericPad For the keycode of a key on the keypad where the same character is also on the main keyboard this flag needs to be <tt>YES</tt>.
*/
- (UInt16)keyCodeForCharacter:(unichar)character numericPad:(BOOL)numericPad;
/*!
@method keyCodeForCharacter:
@abstract Get the key code for a given key character.
@discussion Calls <tt>keyCodeForCharacter:numericPad:</tt> with the keypad flag set to <tt>NO</tt>
@param character The unmodified character on the keyboard.
@result A value specifying the virtual key code that is to be translated. For ADB keyboards, virtual key codes are in the range from 0 to 127.
*/
- (UInt16)keyCodeForCharacter:(unichar)character;
@end

View File

@ -0,0 +1,485 @@
/*
NDKeyboardLayout.m
Created by Nathan Day on 01.18.10 under a MIT-style license.
Copyright (c) 2010 Nathan Day
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#import "NDKeyboardLayout.h"
#include <libkern/OSAtomic.h>
NSString * const NDKeyboardLayoutSelectedKeyboardInputSourceChangedNotification = @"NDKeyboardLayoutSelectedKeyboardInputSourceChanged";
NSString * const NDKeyboardLayoutPreviousKeyboardLayoutUserInfoKey = @"NDKeyboardLayoutPreviousKeyboardLayout";
struct ReverseMappingEntry
{
UniChar character;
BOOL keypad;
UInt16 keyCode;
};
struct UnmappedEntry
{
UniChar character;
UInt16 keyCode;
unichar description[4];
};
struct UnmappedEntry unmappedKeys[] =
{
{NSDeleteFunctionKey, 0x33, {0x232B,'\0','\0','\0'}},
{NSF17FunctionKey, 0x40, {'F','1','7','\0'}},
{NSClearDisplayFunctionKey, 0x47, {0x2327,'\0','\0','\0'}},
{NSF18FunctionKey, 0x4F, {'F','1','8','\0'}},
{NSF19FunctionKey, 0x50, {'F','1','9','\0'}},
{NSF5FunctionKey, 0x60, {'F','5','\0','\0'}},
{NSF6FunctionKey, 0x61, {'F','6','\0','\0'}},
{NSF7FunctionKey, 0x62, {'F','7','\0','\0'}},
{NSF3FunctionKey, 0x63, {'F','3','\0','\0'}},
{NSF8FunctionKey, 0x64, {'F','8','\0','\0'}},
{NSF9FunctionKey, 0x65, {'F','9','\0','\0'}},
{NSF11FunctionKey, 0x67, {'F','1','1','\0'}},
{NSF14FunctionKey, 0x68, {'F','1','4','\0'}},
{NSF13FunctionKey, 0x69, {'F','1','3','\0'}},
{NSF16FunctionKey, 0x6A, {'F','1','6','\0'}},
{NSF10FunctionKey, 0x6D, {'F','1','0','\0'}},
{NSF12FunctionKey, 0x6F, {'F','1','2','\0'}},
{NSF15FunctionKey, 0x71, {'F','1','5','\0'}},
{NSHomeFunctionKey, 0x73, {0x21F1,'\0','\0','\0'}},
{NSPageUpFunctionKey, 0x74, {0x21DE,'\0','\0','\0'}},
{NSDeleteCharFunctionKey, 0x75, {0x2326,'\0','\0','\0'}},
{NSF4FunctionKey, 0x76, {'F','4','\0','\0'}},
{NSEndFunctionKey, 0x77, {0x21F2,'\0','\0','\0'}},
{NSF2FunctionKey, 0x78, {'F','2','\0','\0'}},
{NSPageDownFunctionKey, 0x79, {0x21DF,'\0','\0','\0'}},
{NSF1FunctionKey, 0x7A, {'F','1','\0','\0'}},
{NSLeftArrowFunctionKey, 0x7B, {0x2190,'\0','\0','\0'}},
{NSRightArrowFunctionKey, 0x7C, {0x2192,'\0','\0','\0'}},
{NSDownArrowFunctionKey, 0x7D, {0x2193,'\0','\0','\0'}},
{NSUpArrowFunctionKey, 0x7E, {0x2191,'\0','\0','\0'}}
// {NSF20FunctionKey, 0xXXXX},
// {NSF21FunctionKey, 0xXXXX},
// {NSF22FunctionKey, 0xXXXX},
// {NSF23FunctionKey, 0xXXXX},
// {NSF24FunctionKey, 0xXXXX},
// {NSF25FunctionKey, 0xXXXX},
// {NSF26FunctionKey, 0xXXXX},
// {NSF27FunctionKey, 0xXXXX},
// {NSF28FunctionKey, 0xXXXX},
// {NSF29FunctionKey, 0xXXXX},
// {NSF30FunctionKey, 0xXXXX},
// {NSF31FunctionKey, 0xXXXX},
// {NSF32FunctionKey, 0xXXXX},
// {NSF33FunctionKey, 0xXXXX},
// {NSF34FunctionKey, 0xXXXX},
// {NSF35FunctionKey, 0xXXXX},
// {NSInsertFunctionKey, 0xXXXX},
// {NSBeginFunctionKey, 0xXXXX},
// {NSPrintScreenFunctionKey, 0xXXXX},
// {NSScrollLockFunctionKey, 0xXXXX},
// {NSPauseFunctionKey, 0xXXXX},
// {NSSysReqFunctionKey, 0xXXXX},
// {NSBreakFunctionKey, 0xXXXX},
// {NSResetFunctionKey, 0xXXXX},
// {NSStopFunctionKey, 0xXXXX},
// {NSMenuFunctionKey, 0xXXXX},
// {NSUserFunctionKey, 0xXXXX},
// {NSSystemFunctionKey, 0xXXXX},
// {NSPrintFunctionKey, 0xXXXX},
// {NSClearLineFunctionKey, 0xXXXX},
// {NSInsertLineFunctionKey, 0xXXXX},
// {NSDeleteLineFunctionKey, 0xXXXX},
// {NSInsertCharFunctionKey, 0xXXXX},
// {NSPrevFunctionKey, 0xXXXX},
// {NSNextFunctionKey, 0xXXXX},
// {NSSelectFunctionKey, 0xXXXX},
// {NSExecuteFunctionKey, 0xXXXX},
// {NSUndoFunctionKey, 0xXXXX},
// {NSRedoFunctionKey, 0xXXXX},
// {NSFindFunctionKey, 0xXXXX},
// {NSHelpFunctionKey, 0xXXXX},
// {NSModeSwitchFunctionKey, 0xXXXX}
};
@interface NDKeyboardLayout ()
@property(readonly,nonatomic) const UCKeyboardLayout * keyboardLayoutPtr;
@end
static int _reverseMappingEntryCmpFunc( const void * a, const void * b )
{
struct ReverseMappingEntry * theA = (struct ReverseMappingEntry*)a,
* theB = (struct ReverseMappingEntry*)b;
return theA->character != theB->character ? theA->character - theB->character : theA->keypad - theB->keypad;
}
static struct ReverseMappingEntry * _searchreverseMapping( struct ReverseMappingEntry * aMapping, NSUInteger aLength, struct ReverseMappingEntry * aSearchValue )
{
NSInteger low = 0,
high = aLength - 1,
mid,
result;
while( low <= high )
{
mid = (low + high)>>1;
result = _reverseMappingEntryCmpFunc( &aMapping[mid], aSearchValue );
if( result > 0 )
high = mid - 1;
else if( result < 0 )
low = mid + 1;
else
return &aMapping[mid];
}
return NULL;
}
static struct UnmappedEntry * _unmappedEntryForKeyCode( UInt16 aKeyCode )
{
NSInteger low = 0,
high = sizeof(unmappedKeys)/sizeof(*unmappedKeys) - 1,
mid,
result;
while( low <= high )
{
mid = (low + high)>>1;
result = unmappedKeys[mid].keyCode - aKeyCode;
if( result > 0 )
high = mid - 1;
else if( result < 0 )
low = mid + 1;
else
return &unmappedKeys[mid];
}
return '\0';
}
static const size_t kBufferSize = 4;
static NSUInteger _characterForModifierFlags( unichar aBuff[kBufferSize], UInt32 aModifierFlags )
{
NSUInteger thePos = 0;
memset( aBuff, 0, kBufferSize );
if(aModifierFlags & NSControlKeyMask)
aBuff[thePos++] = kControlUnicode;
if(aModifierFlags & NSAlternateKeyMask)
aBuff[thePos++] = kOptionUnicode;
if(aModifierFlags & NSShiftKeyMask)
aBuff[thePos++] = kShiftUnicode;
if(aModifierFlags & NSCommandKeyMask)
aBuff[thePos++] = kCommandUnicode;
return thePos;
}
/*
* NDCocoaModifierFlagsForCarbonModifierFlags()
*/
NSUInteger NDCocoaModifierFlagsForCarbonModifierFlags( NSUInteger aModifierFlags )
{
NSUInteger theCocoaModifierFlags = 0;
if(aModifierFlags & shiftKey)
theCocoaModifierFlags |= NSShiftKeyMask;
if(aModifierFlags & controlKey)
theCocoaModifierFlags |= NSControlKeyMask;
if(aModifierFlags & optionKey)
theCocoaModifierFlags |= NSAlternateKeyMask;
if(aModifierFlags & cmdKey)
theCocoaModifierFlags |= NSCommandKeyMask;
return theCocoaModifierFlags;
}
/*
* NDCarbonModifierFlagsForCocoaModifierFlags()
*/
NSUInteger NDCarbonModifierFlagsForCocoaModifierFlags( NSUInteger aModifierFlags )
{
NSUInteger theCarbonModifierFlags = 0;
if(aModifierFlags & NSShiftKeyMask)
theCarbonModifierFlags |= shiftKey;
if(aModifierFlags & NSControlKeyMask)
theCarbonModifierFlags |= controlKey;
if(aModifierFlags & NSAlternateKeyMask)
theCarbonModifierFlags |= optionKey;
if(aModifierFlags & NSCommandKeyMask)
theCarbonModifierFlags |= cmdKey;
return theCarbonModifierFlags;
}
@implementation NDKeyboardLayout
#pragma mark Utility Methods
- (void)generateMappings
{
mappings = (struct ReverseMappingEntry*)calloc( 128 + sizeof(unmappedKeys)/sizeof(*unmappedKeys), sizeof(struct ReverseMappingEntry) );
numberOfMappings = 0;
for( NSUInteger i = 0; i < 128; i++ )
{
UInt32 theDeadKeyState = 0;
UniCharCount theLength = 0;
if( UCKeyTranslate( self.keyboardLayoutPtr,
i,
kUCKeyActionDisplay,
0,
LMGetKbdType(),
kUCKeyTranslateNoDeadKeysBit,
&theDeadKeyState,
1,
&theLength,
&mappings[numberOfMappings].character ) == noErr && theLength > 0 && isprint(mappings[numberOfMappings].character) )
{
mappings[numberOfMappings].keyCode = i;
numberOfMappings++;
}
}
/* add unmapped keys */
for( NSUInteger i = 0; i < sizeof(unmappedKeys)/sizeof(*unmappedKeys); i++ )
{
mappings[numberOfMappings].character = unmappedKeys[i].character;
mappings[numberOfMappings].keyCode = unmappedKeys[i].keyCode;
numberOfMappings++;
}
mappings = (struct ReverseMappingEntry*)realloc( (void*)mappings, numberOfMappings*sizeof(struct ReverseMappingEntry) );
// sort so we can perform binary searches
qsort( (void *)mappings, numberOfMappings, sizeof(struct ReverseMappingEntry), _reverseMappingEntryCmpFunc );
/* find keypad keys and set the keypad flag */
for( NSUInteger i = 1; i < numberOfMappings; i++ )
{
NSParameterAssert( mappings[i-1].keyCode != mappings[i].keyCode );
if( mappings[i-1].character == mappings[i].character ) // assume large keycode is a keypad
{
if( mappings[i-1].keyCode > mappings[i].keyCode ) // make the keypad entry is second
{
UInt16 theTemp = mappings[i-1].keyCode;
mappings[i-1].keyCode = mappings[i].keyCode;
mappings[i].keyCode = theTemp;
}
mappings[i].keypad = YES;
}
}
#ifdef DEBUGGING_CODE
for( NSUInteger i = 1; i < numberOfMappings; i++ )
{
fprintf( stderr, "%d -> %c[%d]%s\n",
mappings[i].keyCode,
(char)mappings[i].character,
mappings[i].character,
mappings[i].keypad ? " keypad" : ""
);
NSAssert3( mappings[i-1].character <= mappings[i].character, @"[%d] %d <= %d", i, mappings[i-1].character, mappings[i].character );
}
#endif
}
#pragma mark Constructor Methods
static volatile NDKeyboardLayout * kCurrentKeyboardLayout = nil;
void NDKeyboardLayoutNotificationCallback( CFNotificationCenterRef aCenter, void * self, CFStringRef aName, const void * anObj, CFDictionaryRef aUserInfo )
{
NSDictionary * theUserInfo = [NSDictionary dictionaryWithObject:kCurrentKeyboardLayout forKey:NDKeyboardLayoutPreviousKeyboardLayoutUserInfoKey];
@synchronized(self) { [kCurrentKeyboardLayout release], kCurrentKeyboardLayout = nil; }
[[NSNotificationCenter defaultCenter] postNotificationName:NDKeyboardLayoutSelectedKeyboardInputSourceChangedNotification object:self userInfo:theUserInfo];
}
+ (void)initialize
{
CFNotificationCenterAddObserver( CFNotificationCenterGetLocalCenter(),
(const void *)self,
NDKeyboardLayoutNotificationCallback,
kTISNotifySelectedKeyboardInputSourceChanged,
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately
);
}
+ (id)keyboardLayout
{
if( kCurrentKeyboardLayout == nil )
{
@synchronized(self)
{ /*
Try different method until we succeed.
*/
TISInputSourceRef (*theInputSourceFunctions[])() = {
TISCopyInputMethodKeyboardLayoutOverride,
TISCopyCurrentKeyboardLayoutInputSource,
TISCopyCurrentASCIICapableKeyboardLayoutInputSource
};
for( NSUInteger i = 0; i < sizeof(theInputSourceFunctions)/sizeof(*theInputSourceFunctions) && kCurrentKeyboardLayout == nil; i++ )
{
TISInputSourceRef theInputSource = theInputSourceFunctions[i]();
if( theInputSource != NULL )
{
kCurrentKeyboardLayout = [[self alloc] initWithInputSource:theInputSource];
CFRelease(theInputSource);
}
}
}
}
return kCurrentKeyboardLayout;
}
- (id)init
{
[self release];
return [[NDKeyboardLayout keyboardLayout] retain];
}
- (id)initWithLanguage:(NSString *)aLangauge { return [self initWithInputSource:TISCopyInputSourceForLanguage((CFStringRef)aLangauge)]; }
- (id)initWithInputSource:(TISInputSourceRef)aSource
{
if( (self = [super init]) != nil )
{
if( aSource != NULL && (keyboardLayoutData = (CFDataRef)CFMakeCollectable(TISGetInputSourceProperty(aSource, kTISPropertyUnicodeKeyLayoutData))) != nil )
{
CFRetain( keyboardLayoutData );
}
else
self = nil, [self release];
}
return self;
}
- (void)dealloc
{
if( mappings != NULL )
free( (void*)mappings );
if( keyboardLayoutData != NULL )
CFRelease( keyboardLayoutData );
[super dealloc];
}
- (NSString*)stringForCharacter:(unichar)aCharacter modifierFlags:(UInt32)aModifierFlags
{
return [self stringForKeyCode:[self keyCodeForCharacter:aCharacter numericPad:(aModifierFlags&NSNumericPadKeyMask) != 0] modifierFlags:aModifierFlags];
}
- (NSString*)stringForKeyCode:(UInt16)aKeyCode modifierFlags:(UInt32)aModifierFlags
{
NSString * theResult = nil;
struct UnmappedEntry * theEntry = _unmappedEntryForKeyCode( aKeyCode ); // is it one of the unmapped values
if( theEntry != NULL )
{
unichar theCharacter[sizeof(theEntry->description)/sizeof(*theEntry->description)+4+1];
memset( theCharacter, 0, sizeof(theCharacter) );
NSUInteger thePos = _characterForModifierFlags(theCharacter,aModifierFlags);
memcpy( theCharacter+thePos, theEntry->description, sizeof(theEntry->description) );
theResult = [NSString stringWithCharacters:theCharacter length:sizeof(theEntry->description)/sizeof(*theEntry->description)+thePos];
}
else
{
UInt32 theDeadKeyState = 0;
UniCharCount theLength = 0;
UniChar theCharacter[260];
NSUInteger thePos = _characterForModifierFlags(theCharacter,aModifierFlags);
if( UCKeyTranslate( self.keyboardLayoutPtr, aKeyCode,
kUCKeyActionDisplay,
NDCarbonModifierFlagsForCocoaModifierFlags(aModifierFlags),
LMGetKbdType(),
kUCKeyTranslateNoDeadKeysBit,
&theDeadKeyState,
sizeof(theCharacter)/sizeof(*theCharacter)-thePos,
&theLength,
theCharacter+thePos ) == noErr )
{
theResult = [[NSString stringWithCharacters:theCharacter length:theLength+thePos] uppercaseString];
}
}
return theResult;
}
- (unichar)characterForKeyCode:(UInt16)aKeyCode
{
unichar theChar = 0;
struct UnmappedEntry * theEntry = _unmappedEntryForKeyCode( aKeyCode );
if( theEntry == NULL ) // is it one of the unmapped values
{
UInt32 theDeadKeyState = 0;
UniCharCount theLength = 0;
UniChar theCharacter[256];
if( UCKeyTranslate( self.keyboardLayoutPtr, aKeyCode,
kUCKeyActionDisplay,
0,
LMGetKbdType(),
kUCKeyTranslateNoDeadKeysBit,
&theDeadKeyState,
sizeof(theCharacter)/sizeof(*theCharacter),
&theLength,
theCharacter ) == noErr )
{
theChar = theCharacter[0];
}
}
else
theChar = theEntry->character;
return toupper(theChar);
}
- (UInt16)keyCodeForCharacter:(unichar)aCharacter { return [self keyCodeForCharacter:aCharacter numericPad:NO]; }
- (UInt16)keyCodeForCharacter:(unichar)aCharacter numericPad:(BOOL)aNumericPad
{
struct ReverseMappingEntry theSearchValue = { tolower(aCharacter), aNumericPad, 0 };
struct ReverseMappingEntry * theEntry = NULL;
if( mappings == NULL )
[self generateMappings];
theEntry = _searchreverseMapping( mappings, numberOfMappings, &theSearchValue );
return theEntry ? theEntry->keyCode : '\0';
}
#pragma mark - private
- (const UCKeyboardLayout *)keyboardLayoutPtr { return (const UCKeyboardLayout *)CFDataGetBytePtr(keyboardLayoutData); }
@end

View File

@ -0,0 +1,2 @@
/* Localized versions of Info.plist keys */

View File

@ -32,39 +32,6 @@
<rect key="frame" x="0.0" y="0.0" width="432" height="131"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button verticalHuggingPriority="750" id="30">
<rect key="frame" x="175" y="34" width="64" height="32"/>
<autoresizingMask key="autoresizingMask"/>
<buttonCell key="cell" type="push" title="Edit" bezelStyle="rounded" alignment="center" borderStyle="border" inset="2" id="204">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="grabNextHotKey:" target="6" id="33"/>
</connections>
</button>
<button verticalHuggingPriority="750" id="KcI-9g-270">
<rect key="frame" x="175" y="9" width="64" height="32"/>
<autoresizingMask key="autoresizingMask"/>
<buttonCell key="cell" type="push" title="Edit" bezelStyle="rounded" alignment="center" borderStyle="border" inset="2" id="6zz-ME-x1V">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="grabSpamHotKey:" target="6" id="wyh-q1-p3g"/>
</connections>
</button>
<button verticalHuggingPriority="750" id="29">
<rect key="frame" x="175" y="59" width="64" height="32"/>
<autoresizingMask key="autoresizingMask"/>
<buttonCell key="cell" type="push" title="Edit" bezelStyle="rounded" alignment="center" borderStyle="border" inset="2" id="203">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="grabPrevHotKey:" target="6" id="32"/>
</connections>
</button>
<textField verticalHuggingPriority="750" id="28" customClass="HotKeyControl">
<rect key="frame" x="91" y="42" width="82" height="19"/>
<autoresizingMask key="autoresizingMask"/>
@ -128,18 +95,6 @@
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" id="17">
<rect key="frame" x="175" y="84" width="64" height="32"/>
<autoresizingMask key="autoresizingMask"/>
<buttonCell key="cell" type="push" title="Edit" bezelStyle="rounded" alignment="center" borderStyle="border" inset="2" id="197">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="grabPlayHotKey:" target="6" id="31"/>
<outlet property="nextKeyView" destination="16" id="23"/>
</connections>
</button>
<textField verticalHuggingPriority="750" id="16" customClass="HotKeyControl">
<rect key="frame" x="91" y="92" width="82" height="19"/>
<autoresizingMask key="autoresizingMask"/>
@ -150,7 +105,6 @@
</textFieldCell>
<connections>
<action selector="hotKeyChanged:" target="6" id="20"/>
<outlet property="nextKeyView" destination="17" id="22"/>
</connections>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="eid-M4-6Cs">

View File

@ -21,6 +21,7 @@
17E78B6A0D68C1E3005C5A59 /* Preferences.xib in Resources */ = {isa = PBXBuildFile; fileRef = 17E78B680D68C1E3005C5A59 /* Preferences.xib */; };
8384917718084D9F00E7332D /* appearance.png in Resources */ = {isa = PBXBuildFile; fileRef = 8384917518084D9F00E7332D /* appearance.png */; };
8384917818084D9F00E7332D /* growl.png in Resources */ = {isa = PBXBuildFile; fileRef = 8384917618084D9F00E7332D /* growl.png */; };
8384918C1808596A00E7332D /* NDHotKey.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 838491841808588D00E7332D /* NDHotKey.framework */; };
83EF495F17FBC96A00642E3C /* VolumeBehaviorArrayController.m in Sources */ = {isa = PBXBuildFile; fileRef = 83EF495E17FBC96A00642E3C /* VolumeBehaviorArrayController.m */; };
8D5B49B4048680CD000E48DA /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */; };
8E07AA880AAC8EA200A4B32F /* HotKeyPane.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E07AA810AAC8EA200A4B32F /* HotKeyPane.m */; };
@ -28,13 +29,41 @@
8E07AA8A0AAC8EA200A4B32F /* GeneralPreferencesPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E07AA850AAC8EA200A4B32F /* GeneralPreferencesPlugin.m */; };
8E07ABDD0AAC95BC00A4B32F /* hot_keys.png in Resources */ = {isa = PBXBuildFile; fileRef = 8E07ABDB0AAC95BC00A4B32F /* hot_keys.png */; };
8E15A86C0B894768006DC802 /* updates.png in Resources */ = {isa = PBXBuildFile; fileRef = 8E15A86B0B894768006DC802 /* updates.png */; };
8E6C12160AACAE4100819171 /* NDHotKeyControl.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E6C12130AACAE4100819171 /* NDHotKeyControl.m */; };
8E6C12170AACAE4100819171 /* NDHotKeyEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E6C12150AACAE4100819171 /* NDHotKeyEvent.m */; };
8E6C123A0AACAEF200819171 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8E6C12390AACAEF200819171 /* Carbon.framework */; };
8E6C13A00AACBAB500819171 /* HotKeyControl.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E6C139F0AACBAB500819171 /* HotKeyControl.m */; };
99F1813F0DE01D7A00FD5FFB /* PlaylistBehaviorArrayController.m in Sources */ = {isa = PBXBuildFile; fileRef = 99F1813E0DE01D7A00FD5FFB /* PlaylistBehaviorArrayController.m */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
838491831808588D00E7332D /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 8384917F1808588D00E7332D /* NDHotKey.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 32F1615614E6BB3B00D6AB2F;
remoteInfo = NDHotKey;
};
838491891808594800E7332D /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 8384917F1808588D00E7332D /* NDHotKey.xcodeproj */;
proxyType = 1;
remoteGlobalIDString = 32F1615514E6BB3B00D6AB2F;
remoteInfo = NDHotKey;
};
/* End PBXContainerItemProxy section */
/* Begin PBXCopyFilesBuildPhase section */
8384918B1808595500E7332D /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
8384918C1808596A00E7332D /* NDHotKey.framework in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
089C1672FE841209C02AAC07 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
089C167EFE841241C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
@ -59,6 +88,7 @@
8384913618081ECB00E7332D /* Logging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Logging.h; path = ../../Utils/Logging.h; sourceTree = "<group>"; };
8384917518084D9F00E7332D /* appearance.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = appearance.png; path = Icons/appearance.png; sourceTree = "<group>"; };
8384917618084D9F00E7332D /* growl.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = growl.png; path = Icons/growl.png; sourceTree = "<group>"; };
8384917F1808588D00E7332D /* NDHotKey.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = NDHotKey.xcodeproj; path = ../../Frameworks/NDHotKey/NDHotKey.xcodeproj; sourceTree = "<group>"; };
83EF495D17FBC96A00642E3C /* VolumeBehaviorArrayController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VolumeBehaviorArrayController.h; sourceTree = "<group>"; };
83EF495E17FBC96A00642E3C /* VolumeBehaviorArrayController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VolumeBehaviorArrayController.m; sourceTree = "<group>"; };
8D5B49B6048680CD000E48DA /* General.preferencePane */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = General.preferencePane; sourceTree = BUILT_PRODUCTS_DIR; };
@ -71,10 +101,6 @@
8E07AA850AAC8EA200A4B32F /* GeneralPreferencesPlugin.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = GeneralPreferencesPlugin.m; sourceTree = "<group>"; };
8E07ABDB0AAC95BC00A4B32F /* hot_keys.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = hot_keys.png; path = Icons/hot_keys.png; sourceTree = "<group>"; };
8E15A86B0B894768006DC802 /* updates.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = updates.png; path = Icons/updates.png; sourceTree = "<group>"; };
8E6C12120AACAE4100819171 /* NDHotKeyControl.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = NDHotKeyControl.h; sourceTree = "<group>"; };
8E6C12130AACAE4100819171 /* NDHotKeyControl.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = NDHotKeyControl.m; sourceTree = "<group>"; };
8E6C12140AACAE4100819171 /* NDHotKeyEvent.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = NDHotKeyEvent.h; sourceTree = "<group>"; };
8E6C12150AACAE4100819171 /* NDHotKeyEvent.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = NDHotKeyEvent.m; sourceTree = "<group>"; };
8E6C12390AACAEF200819171 /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = /System/Library/Frameworks/Carbon.framework; sourceTree = "<absolute>"; };
8E6C139E0AACBAB500819171 /* HotKeyControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HotKeyControl.h; sourceTree = "<group>"; };
8E6C139F0AACBAB500819171 /* HotKeyControl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HotKeyControl.m; sourceTree = "<group>"; };
@ -145,6 +171,7 @@
1058C7ACFEA557BF11CA2CBB /* Linked Frameworks */ = {
isa = PBXGroup;
children = (
8384917F1808588D00E7332D /* NDHotKey.xcodeproj */,
8E6C12390AACAEF200819171 /* Carbon.framework */,
1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */,
);
@ -179,10 +206,6 @@
children = (
170744AB0BFF3938002475C9 /* AppcastArrayController.h */,
170744AC0BFF3938002475C9 /* AppcastArrayController.m */,
8E6C12120AACAE4100819171 /* NDHotKeyControl.h */,
8E6C12130AACAE4100819171 /* NDHotKeyControl.m */,
8E6C12140AACAE4100819171 /* NDHotKeyEvent.h */,
8E6C12150AACAE4100819171 /* NDHotKeyEvent.m */,
8E6C139E0AACBAB500819171 /* HotKeyControl.h */,
8E6C139F0AACBAB500819171 /* HotKeyControl.m */,
17C643370B8A77CC00C53518 /* OutputsArrayController.h */,
@ -211,6 +234,14 @@
name = "Other Sources";
sourceTree = "<group>";
};
838491801808588D00E7332D /* Products */ = {
isa = PBXGroup;
children = (
838491841808588D00E7332D /* NDHotKey.framework */,
);
name = Products;
sourceTree = "<group>";
};
8E07ABD90AAC95AF00A4B32F /* Icons */ = {
isa = PBXGroup;
children = (
@ -237,10 +268,12 @@
8D5B49AF048680CD000E48DA /* Resources */,
8D5B49B1048680CD000E48DA /* Sources */,
8D5B49B3048680CD000E48DA /* Frameworks */,
8384918B1808595500E7332D /* CopyFiles */,
);
buildRules = (
);
dependencies = (
8384918A1808594800E7332D /* PBXTargetDependency */,
);
name = General;
productInstallPath = "$(HOME)/Library/Bundles";
@ -272,6 +305,12 @@
);
mainGroup = 089C166AFE841209C02AAC07 /* General */;
projectDirPath = "";
projectReferences = (
{
ProductGroup = 838491801808588D00E7332D /* Products */;
ProjectRef = 8384917F1808588D00E7332D /* NDHotKey.xcodeproj */;
},
);
projectRoot = "";
targets = (
8D5B49AC048680CD000E48DA /* General */,
@ -279,6 +318,16 @@
};
/* End PBXProject section */
/* Begin PBXReferenceProxy section */
838491841808588D00E7332D /* NDHotKey.framework */ = {
isa = PBXReferenceProxy;
fileType = wrapper.framework;
path = NDHotKey.framework;
remoteRef = 838491831808588D00E7332D /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
/* End PBXReferenceProxy section */
/* Begin PBXResourcesBuildPhase section */
8D5B49AF048680CD000E48DA /* Resources */ = {
isa = PBXResourcesBuildPhase;
@ -309,8 +358,6 @@
8E07AA880AAC8EA200A4B32F /* HotKeyPane.m in Sources */,
8E07AA890AAC8EA200A4B32F /* GeneralPreferencePane.m in Sources */,
8E07AA8A0AAC8EA200A4B32F /* GeneralPreferencesPlugin.m in Sources */,
8E6C12160AACAE4100819171 /* NDHotKeyControl.m in Sources */,
8E6C12170AACAE4100819171 /* NDHotKeyEvent.m in Sources */,
8E6C13A00AACBAB500819171 /* HotKeyControl.m in Sources */,
83EF495F17FBC96A00642E3C /* VolumeBehaviorArrayController.m in Sources */,
17C643380B8A77CC00C53518 /* OutputsArrayController.m in Sources */,
@ -322,6 +369,14 @@
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */
8384918A1808594800E7332D /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
name = NDHotKey;
targetProxy = 838491891808594800E7332D /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */
/* Begin PBXVariantGroup section */
178E386D0C3DA64500EE6711 /* InfoPlist.strings */ = {
isa = PBXVariantGroup;

View File

@ -7,22 +7,9 @@
//
#import <Cocoa/Cocoa.h>
#import "NDHotKeyControl.h"
#import <NDHotKey/NDHotKeyControl.h>
@interface HotKeyControl : NDHotKeyControl {
BOOL observing;
}
- (void)enableAllHotKeys;
- (void)disableAllHotKeys;
- (void)startObserving;
- (void)stopObserving;
- (void)setKeyCode: (unsigned short)k;
- (void)setCharacter: (unichar)c;
- (void)setModifierFlags: (unsigned long)m;
- (void)updateStringValue;
@end

View File

@ -7,113 +7,15 @@
//
#import "HotKeyControl.h"
#import "NDHotKeyEvent.h"
typedef int CGSConnection;
typedef enum {
CGSGlobalHotKeyEnable = 0,
CGSGlobalHotKeyDisable = 1,
} CGSGlobalHotKeyOperatingMode;
extern CGSConnection _CGSDefaultConnection(void);
extern CGError CGSGetGlobalHotKeyOperatingMode(
CGSConnection connection, CGSGlobalHotKeyOperatingMode *mode);
extern CGError CGSSetGlobalHotKeyOperatingMode(CGSConnection connection,
CGSGlobalHotKeyOperatingMode mode);
#import <NDHotKey/NDHotKeyEvent.h>
@implementation HotKeyControl
- (void)awakeFromNib
{
observing = NO;
}
- (void)disableAllHotKeys
{
CGSConnection conn = _CGSDefaultConnection();
CGSSetGlobalHotKeyOperatingMode(conn, CGSGlobalHotKeyDisable);
}
- (void)enableAllHotKeys
{
CGSConnection conn = _CGSDefaultConnection();
CGSSetGlobalHotKeyOperatingMode(conn, CGSGlobalHotKeyEnable);
}
- (void)startObserving
{
[self disableAllHotKeys];
observing = YES;
[self setStringValue:NSLocalizedStringFromTableInBundle(@"Press Key...", nil, [NSBundle bundleForClass:[self class]], @"")];
}
- (void)stopObserving
{
[self enableAllHotKeys];
observing = NO;
[self updateStringValue];
}
- (BOOL)becomeFirstResponder
{
[self startObserving];
return YES;
}
- (BOOL)resignFirstResponder
{
[self stopObserving];
return YES;
}
- (BOOL)performKeyEquivalent:(NSEvent*)anEvent
{
if (observing == YES)
{
return [super performKeyEquivalent:anEvent];
}
else
{
return NO;
}
}
- (void)keyDown:(NSEvent *)theEvent
{
if (observing == YES)
{
[super keyDown:theEvent];
}
}
- (void)mouseDown:(NSEvent *)theEvent
{
[self startObserving];
[self setStringValue:NSLocalizedStringFromTableInBundle(@"Press Key...", nil, [NSBundle bundleForClass:[self class]], @"")];
[self setRequiresModifierKeys:YES];
[self setReadyForHotKeyEvent:YES];
}
- (void)setKeyCode: (unsigned short)k
{
keyCode = k;
}
- (void)setCharacter: (unichar)c
{
character = c;
}
- (void)setModifierFlags: (unsigned long)m
{
modifierFlags = m;
}
- (void)updateStringValue
{
[self setStringValue:stringForKeyCodeAndModifierFlags( keyCode, character, modifierFlags )];
}
@end

View File

@ -17,11 +17,6 @@
IBOutlet HotKeyControl *spamHotKeyControl;
}
- (IBAction) grabPlayHotKey:(id)sender;
- (IBAction) grabPrevHotKey:(id)sender;
- (IBAction) grabNextHotKey:(id)sender;
- (IBAction) grabSpamHotKey:(id)sender;
- (IBAction) hotKeyChanged:(id)sender;
@end

View File

@ -7,113 +7,56 @@
//
#import "HotKeyPane.h"
#import "NDHotKeyEvent.h"
#import "NDHotKey/NDHotKeyEvent.h"
#import "NDHotKey/NDKeyboardLayout.h"
#import "HotKeyControl.h"
@implementation HotKeyPane
static void setControlText(HotKeyControl* control, NSString* kcprop, NSString* mprop)
{
UInt16 keyCode = [[NSUserDefaults standardUserDefaults] integerForKey:kcprop];
NSUInteger modifiers = [[NSUserDefaults standardUserDefaults] integerForKey:mprop];
NSString *str = [[NDKeyboardLayout keyboardLayout] stringForKeyCode:keyCode modifierFlags:modifiers];
[control setStringValue:str];
}
- (void)awakeFromNib
{
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object: [view window]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object: [view window]];
[prevHotKeyControl setKeyCode: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyPreviousKeyCode"] ];
[prevHotKeyControl setCharacter: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyPreviousCharacter"] ];
[prevHotKeyControl setModifierFlags: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyPreviousModifiers"] ];
[prevHotKeyControl updateStringValue];
[nextHotKeyControl setKeyCode: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyNextKeyCode"] ];
[nextHotKeyControl setCharacter: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyNextCharacter"] ];
[nextHotKeyControl setModifierFlags: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyNextModifiers"] ];
[nextHotKeyControl updateStringValue];
[playHotKeyControl setKeyCode: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyPlayKeyCode"] ];
[playHotKeyControl setCharacter: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyPlayCharacter"] ];
[playHotKeyControl setModifierFlags: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyPlayModifiers"] ];
[playHotKeyControl updateStringValue];
[spamHotKeyControl setKeyCode: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeySpamKeyCode"] ];
[spamHotKeyControl setCharacter: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeySpamCharacter"] ];
[spamHotKeyControl setModifierFlags: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeySpamModifiers"] ];
[spamHotKeyControl updateStringValue];
setControlText(prevHotKeyControl, @"hotKeyPreviousKeyCode", @"hotKeyPreviousModifiers");
setControlText(nextHotKeyControl, @"hotKeyNextKeyCode", @"hotKeyNextModifiers");
setControlText(playHotKeyControl, @"hotKeyPlayKeyCode", @"hotKeyPlayModifiers");
setControlText(spamHotKeyControl, @"hotKeySpamKeyCode", @"hotKeySpamModifiers");
}
- (NSString *)title
{
return NSLocalizedStringFromTableInBundle(@"Hot Keys", nil, [NSBundle bundleForClass:[self class]], @"");
return NSLocalizedStringFromTableInBundle(@"Hot Keys", nil, [NSBundle bundleForClass:[self class]], @"");
}
- (NSImage *)icon
{
return [[[NSImage alloc] initWithContentsOfFile:[[NSBundle bundleForClass:[self class]] pathForImageResource:@"hot_keys"]] autorelease];
}
/*- (void)windowDidBecomeKey:(id)notification
{
if ([notification object] == [view window]) {
[playHotKeyControl startObserving];
[prevHotKeyControl startObserving];
[nextHotKeyControl startObserving];
}
}
*/
- (void)windowDidResignKey:(id)notification
{
if ([notification object] == [view window]) {
[playHotKeyControl stopObserving];
[prevHotKeyControl stopObserving];
[nextHotKeyControl stopObserving];
[spamHotKeyControl stopObserving];
}
}
- (IBAction) grabPlayHotKey:(id)sender
{
[playHotKeyControl startObserving];
}
- (IBAction) grabPrevHotKey:(id)sender
{
[prevHotKeyControl startObserving];
}
- (IBAction) grabNextHotKey:(id)sender
{
[nextHotKeyControl startObserving];
}
- (IBAction) grabSpamHotKey:(id)sender
{
[spamHotKeyControl startObserving];
return [[[NSImage alloc] initWithContentsOfFile:[[NSBundle bundleForClass:[self class]] pathForImageResource:@"hot_keys"]] autorelease];
}
- (IBAction) hotKeyChanged:(id)sender
{
if (sender == playHotKeyControl) {
[[NSUserDefaults standardUserDefaults] setInteger:[playHotKeyControl character] forKey:@"hotKeyPlayCharacter"];
[[NSUserDefaults standardUserDefaults] setInteger:[playHotKeyControl modifierFlags] forKey:@"hotKeyPlayModifiers"];
[[NSUserDefaults standardUserDefaults] setInteger:[playHotKeyControl keyCode] forKey:@"hotKeyPlayKeyCode"];
}
else if (sender == prevHotKeyControl) {
[[NSUserDefaults standardUserDefaults] setInteger:[prevHotKeyControl character] forKey:@"hotKeyPreviousCharacter"];
[[NSUserDefaults standardUserDefaults] setInteger:[prevHotKeyControl modifierFlags] forKey:@"hotKeyPreviousModifiers"];
[[NSUserDefaults standardUserDefaults] setInteger:[prevHotKeyControl keyCode] forKey:@"hotKeyPreviousKeyCode"];
}
else if (sender == nextHotKeyControl) {
[[NSUserDefaults standardUserDefaults] setInteger:[nextHotKeyControl character] forKey:@"hotKeyNextCharacter"];
[[NSUserDefaults standardUserDefaults] setInteger:[nextHotKeyControl modifierFlags] forKey:@"hotKeyNextModifiers"];
[[NSUserDefaults standardUserDefaults] setInteger:[nextHotKeyControl keyCode] forKey:@"hotKeyNextKeyCode"];
}
else if (sender == spamHotKeyControl) {
[[NSUserDefaults standardUserDefaults] setInteger:[spamHotKeyControl character] forKey:@"hotKeySpamCharacter"];
[[NSUserDefaults standardUserDefaults] setInteger:[spamHotKeyControl modifierFlags] forKey:@"hotKeySpamModifiers"];
[[NSUserDefaults standardUserDefaults] setInteger:[spamHotKeyControl keyCode] forKey:@"hotKeySpamKeyCode"];
}
[sender stopObserving];
if (sender == playHotKeyControl) {
[[NSUserDefaults standardUserDefaults] setInteger:[playHotKeyControl modifierFlags] forKey:@"hotKeyPlayModifiers"];
[[NSUserDefaults standardUserDefaults] setInteger:[playHotKeyControl keyCode] forKey:@"hotKeyPlayKeyCode"];
}
else if (sender == prevHotKeyControl) {
[[NSUserDefaults standardUserDefaults] setInteger:[prevHotKeyControl modifierFlags] forKey:@"hotKeyPreviousModifiers"];
[[NSUserDefaults standardUserDefaults] setInteger:[prevHotKeyControl keyCode] forKey:@"hotKeyPreviousKeyCode"];
}
else if (sender == nextHotKeyControl) {
[[NSUserDefaults standardUserDefaults] setInteger:[nextHotKeyControl modifierFlags] forKey:@"hotKeyNextModifiers"];
[[NSUserDefaults standardUserDefaults] setInteger:[nextHotKeyControl keyCode] forKey:@"hotKeyNextKeyCode"];
}
else if (sender == spamHotKeyControl) {
[[NSUserDefaults standardUserDefaults] setInteger:[nextHotKeyControl modifierFlags] forKey:@"hotKeySpamModifiers"];
[[NSUserDefaults standardUserDefaults] setInteger:[nextHotKeyControl keyCode] forKey:@"hotKeySpamKeyCode"];
}
}
@end

View File

@ -1,76 +0,0 @@
/*!
@header NDHotKeyControl.h
@abstract Header file for a subclass of NSTextField for getting hot key combinations from the user.
@discussion The <tt>NDHotKeyControl</tt> can be used to get a <tt>NDHotKeyEvent</tt> for the last key combination pressed by the user.
Created by Nathan Day on Wed Mar 05 2003.
Copyright (c) 2002 Nathan Day. All rights reserved.
*/
#import <AppKit/AppKit.h>
@class NDHotKeyEvent;
/*
@class NDHotKeyControl
@abstract Subclass of NSTextField for getting hot key combinations from the user.
@discussion The <tt>NDHotKeyControl</tt> can be used to get a <tt>NDHotKeyEvent</tt> for the last key combination pressed by the user.
*/
@interface NDHotKeyControl : NSTextField
{
@protected
unsigned short keyCode;
unichar character;
unsigned long modifierFlags;
BOOL requiresModifierKeys;
}
/*!
@method keyCode
@abstract Get key code.
@discussion Returns the key code for the last key combination the user pressed while the reciever was active.
@result A <tt>unsigned short</tt> containing key code.
*/
- (unsigned short)keyCode;
/*!
@method character
@abstract Get unicode character.
@discussion Returns the unicode character for the last key combination the user pressed while the reciever was active.
@result A <tt>unichar</tt> containing character.
*/
- (unichar)character;
/*!
@method modifierFlags
@abstract Get modifer flags.
@discussion Returns the modifer flags for the last key combination the user pressed while the reciever was active.
@result A <tt>unsigned long</tt> containing modifer flags.
*/
- (unsigned long)modifierFlags;
/*!
@method hotKeyEvent
@abstract Get <tt>NDHotKeyEvent</tt>
@discussion Returns the <tt>NDHotKeyEvent</tt> instance for the last key combination the user pressed while the reciever was active. The <tt>NDHotKeyEvent</tt> returned will either be one that has already been created or a newly created one otherwise.
@result A <tt>NDHotKeyEvent</tt> for the hot key event.
*/
- (NDHotKeyEvent *)hotKeyEvent;
/*!
@method setRequiresModifierKeys:
@abstract Set whether hot keys entered need modifiers keys.
@discussion This does not include function key which do not require modifier keys no matter what the value you pass for the argument <tt><i>flag</i></tt>
@param flag If <tt>NO</tt> then the reciever only accepts hot keys combination containing modifer keys.
*/
- (void)setRequiresModifierKeys:(BOOL)flag;
/*!
@method requiresModifierKeys
@abstract Returns whether hot keys entered need modifiers keys.
@discussion This does not include key which do not require modifier keys no matter what the value is returned.
@result If <tt>NO</tt> then the reciever only accepts hot keys combination containing modifer keys.
*/
- (BOOL)requiresModifierKeys;
@end

View File

@ -1,116 +0,0 @@
/*
* NDHotKeyControl.m
* NDHotKeyEvent
*
* Created by Nathan Day on Wed Mar 05 2003.
* Copyright (c) 2002 Nathan Day. All rights reserved.
*/
#import "NDHotKeyControl.h"
#import "NDHotKeyEvent.h"
/*
* class implementation NDHotKeyControl
*/
@implementation NDHotKeyControl
/*
* -initWithFrame:
*/
- (id)initWithFrame:(NSRect)aFrame
{
if ( self = [super initWithFrame:aFrame] )
{
[self setEditable:NO];
requiresModifierKeys = YES;
}
return self;
}
/*
* -initWithCoder:
*/
- (id)initWithCoder:(NSCoder *)aCoder
{
if ( self = [super initWithCoder:aCoder] )
{
[self setEditable:NO];
requiresModifierKeys = YES;
}
return self;
}
/*
* -keyCode
*/
- (unsigned short)keyCode
{
return keyCode;
}
/*
* -character
*/
- (unichar)character
{
return character;
}
/*
* -modifierFlags
*/
- (unsigned long)modifierFlags
{
return modifierFlags;
}
/*
* -performKeyEquivalent:
*/
- (BOOL)performKeyEquivalent:(NSEvent*)anEvent
{
[self keyDown:anEvent];
return YES;
}
/*
* -keyDown:
*/
- (void)keyDown:(NSEvent *)theEvent
{
unsigned long theModifierFlags = [theEvent modifierFlags];
unichar theChar = [[theEvent charactersIgnoringModifiers] characterAtIndex:0];
theModifierFlags &= (NSShiftKeyMask|NSControlKeyMask|NSAlternateKeyMask|NSCommandKeyMask);
if( (theModifierFlags != 0 || !requiresModifierKeys || theChar > 255) && theChar != 0 )
{
keyCode = [theEvent keyCode];
modifierFlags = theModifierFlags;
character = theChar;
[self setStringValue:stringForKeyCodeAndModifierFlags( keyCode, character, modifierFlags )];
[self performClick:self];
}
}
/*
* -hotKeyEvent
*/
- (NDHotKeyEvent *)hotKeyEvent
{
return [NDHotKeyEvent getHotKeyForKeyCode:[self keyCode] character:[self character] modifierFlags:[self modifierFlags]];
}
- (void)setRequiresModifierKeys:(BOOL)aFlag
{
requiresModifierKeys = aFlag;
}
- (BOOL)requiresModifierKeys
{
return requiresModifierKeys;
}
@end

View File

@ -1,427 +0,0 @@
/*!
@header NDHotKeyEvent.h
@abstract Header file for the class <tt>NDHotKeyEvent</tt>
@discussion <p><tt>NDHotKeyEvent</tt> provides a thread safe Objective-C interface to HotKey events as well as some additional feature to key track of all the hot keys in your application.</p>
<p><h4>Thread Saftey</h4>By default the class object <tt>NDHotKeyEvent</tt> is not thread safe as the underlying functions that it relies on are not thread safe and the mechanism for keeping track of all of the <tt>NDHotKeyEvent</tt> instances is not thread safe either. Thread saftey can be enable be defining the flag <tt>NDHotKeyEventThreadSafe</tt> before compiling.</p>
<p>Even with the flag <tt>NDHotKeyEventThreadSafe</tt> defined instances of <tt>NDHotKeyEvent</tt> will still not be thread safe, that is, it is safe to invoke methods of different instance with different threads as well as class methods, but it is not safe to invoke methods of the same instance with different threads.</p>
<p>The functions <tt>stringForKeyCodeAndModifierFlags</tt> and <tt>unicharForKeyCode</tt> are never thread safe.</p>
<p>Created by Nathan Day on Wed Feb 26 2003.<br>
Copyright &copy; 2002 Nathan Day. All rights reserved.</p>
*/
#import <Cocoa/Cocoa.h>
#import <Carbon/Carbon.h>
/*!
@defined NDHotKeyEventThreadSafe
@abstract A flag to enable thread safety.
@discussion By default the class object <tt>NDHotKeyEvent</tt> is not thread safe. Defining the this flag will make th class methods of <tt>NDHotKeyEvent</tt> thread safe, see introduction for more details..
*/
enum
{
/*!
@const NDHotKeyNoEvent
@abstract A value returned from the method <tt>-[NDHotKeyEvent currentEventType]</tt>
@discussion This value is returned if the hot key has not been pressed yet.
*/
NDHotKeyNoEvent = 0,
/*!
@const NDHotKeyPressedEvent
@abstract A value returned from the method <tt>-[NDHotKeyEvent currentEventType]</tt>
@discussion This value is returned if hot key was pressed last.
*/
NDHotKeyPressedEvent,
/*!
@const NDHotKeyReleasedEvent
@abstract A value returned from the method <tt>-[NDHotKeyEvent currentEventType]</tt>
@discussion This value is returned if hot key was released last.
*/
NDHotKeyReleasedEvent
};
/*!
@const NDHotKeyDefaultSignature
@abstract The default signature
@discussion This is the default signature that will be used if you start using <tt>NDHotKeyEvent</tt> without setting the signature first.
*/
extern const OSType NDHotKeyDefaultSignature;
/*!
@class NDHotKeyEvent
@abstract Class to represent a HotKey
@discussion <p>This class is a wrapper for Carbon Event HotKeys and provides some feature to key track of all the hot keys in your application. It can be used to be notified of key down as well as key up evernts and when a hot key is being taken by another object (see the protocol <tt>NDHotKeyEventTragetWillChange</tt>)</p>
*/
@interface NDHotKeyEvent : NSObject <NSCoding>
{
@private
EventHotKeyRef reference;
unsigned short keyCode;
unichar character;
unsigned int modifierFlags;
int currentEventType;
id target;
SEL selectorReleased,
selectorPressed;
struct
{
unsigned individual : 1;
unsigned collective : 1;
} isEnabled;
}
/*!
@method install
@abstract Install the event key handler
@discussion <tt>install</tt> is called before hot keys can be used. You normally don't need to invoke this method your self but in a multithreaded you might want to invoke this method before creating any threads. <tt>install</tt> is designed to be thread safe but the effects of calling Apples <tt>InstallEventHandler()</tt> funtion from anything other than the main thread is unknown.
@result Returns true if <tt>install</tt> succeeded.
*/
+ (BOOL)install;
/*!
@method setSignature:
@abstract Set the hot key signature for this application
@discussion This should only be called once, before trying to enable any hot keys.
@param signature The four char code signature to identify all hot keys for this application, could your applications signature.
*/
+ (void)setSignature:(OSType)signature;
/*!
@method signature
@abstract Get the hot key signature for this application
@discussion Used to identify the hot key handler for this application.
@result The four char code signature.
*/
+ (OSType)signature;
/*!
@method setAllEnabled:
@abstract Set enabled for all instances of <tt>NDHotKeyEvent</tt>
@discussion Used to enable or disable all hot keys. This method is not the same as sending the message <tt>setEnabled:</tt> to every single <tt>NDHotKeyEvent</tt> instance. Enabling with this method only enables the hot keys that where enable prior to using this method to disable all hot keys.
@param flag <tt>YES</tt> to enable, <tt>NO</tt> to disable.
@result Returns <tt>YES</tt> if succesful.
*/
+ (BOOL)setAllEnabled:(BOOL)flag;
/*!
@method isEnabledKeyCode:modifierFlags:
@abstract Is hot key combination enabled.
@abstract Test to see if a key code and modifier flaf combination are enabled.
@param keyCode The key code used by the keyboard, can vary across hardware.
@param modifierFlags The modifer flags, ( <tt>NSCommandKeyMask</tt>, <tt>NSControlKeyMask</tt>, <tt>NSAlternateKeyMask</tt>, <tt>NSShiftKeyMask</tt> ).
@result Returns <tt>YES</tt> if enabled.
*/
+ (BOOL)isEnabledKeyCode:(unsigned short)keyCode modifierFlags:(unsigned int)modifierFlags;
/*!
@method getHotKeyForKeyCode:modifierFlags:
@abstract Get an <tt>NDHotKeyEvent</tt>
@discussion Gets a <tt>NDHotKeyEvent</tt> for the supplied key code and modifer flags by either finding one that has already been created or by creating a new one..
@param keyCode The key code used by the keyboard, can vary across hardware.
@param aChar The character, used for display purposes only.
@param modifierFlags The modifer flags, ( <tt>NSCommandKeyMask</tt>, <tt>NSControlKeyMask</tt>, <tt>NSAlternateKeyMask</tt>, <tt>NSShiftKeyMask</tt> ).
@result The <tt>NDHotKeyEvent</tt> obejct or nil if failure.
*/
+ (NDHotKeyEvent *)getHotKeyForKeyCode:(unsigned short)keyCode character:(unichar)aChar modifierFlags:(unsigned int)modifierFlags;
/*!
@method findHotKeyForKeyCode:modifierFlags:
@abstract Find an <tt>NDHotKeyEvent</tt>
@discussion Finds the <tt>NDHotKeyEvent</tt> for the supplied key code and modifer flags.
@param keyCode The key code used by the keyboard, can vary across hardware.
@param modifierFlags The modifer flags, ( <tt>NSCommandKeyMask</tt>, <tt>NSControlKeyMask</tt>, <tt>NSAlternateKeyMask</tt>, <tt>NSShiftKeyMask</tt> ).
@result The <tt>NDHotKeyEvent</tt> obejct or nil if none found.
*/
+ (NDHotKeyEvent *)findHotKeyForKeyCode:(unsigned short)keyCode modifierFlags:(unsigned int)modifierFlags;
/*!
@method hotKeyWithKeyCode:character:modifierFlags:
@abstract Get a <tt>NDHotKeyEvent</tt> object.
@discussion Returns a new hot key for the supplied hot key combination, if there is already a hot key for the supplied key code and modifer flags then nil is returned.
@param keyCode The key code used by the keyboard, can vary across hardware.
@param aChar The character, used for display purposes only.
@param modifierFlags The modifer flags, ( <tt>NSCommandKeyMask</tt>, <tt>NSControlKeyMask</tt>, <tt>NSAlternateKeyMask</tt>, <tt>NSShiftKeyMask</tt> ).
@result An new <tt>NDHotKeyEvent</tt> or nil if failure.
*/
+ (id)hotKeyWithKeyCode:(unsigned short)keyCode character:(unichar)aChar modifierFlags:(unsigned int)modifer;
/*!
@method hotKeyWithKeyCode:character:modifierFlags:target:selector:
@abstract Get a <tt>NDHotKeyEvent</tt> object.
@discussion Returns a new hot key for the supplied hot key combination and target object and selector, if there is already a hot key for the supplied key code and modifer flags then nil is returned.
@param keyCode The key code used by the keyboard, can vary across hardware.
@param aChar The character, used for display purposes only.
@param modifierFlags The modifer flags, ( <tt>NSCommandKeyMask</tt>, <tt>NSControlKeyMask</tt>, <tt>NSAlternateKeyMask</tt>, <tt>NSShiftKeyMask</tt> ).
@param target The target of hot key event.
@param selector The selector sent when hot key is released
@result A new <tt>NDHotKeyEvent</tt>
*/
+ (id)hotKeyWithKeyCode:(unsigned short)keyCode character:(unichar)aChar modifierFlags:(unsigned int)modifer target:(id)target selector:(SEL)selector;
/*!
@method initWithPropertyList:
@abstract creates a <tt>NDHotKeyEvent</tt> with a property list.
@discussion This can be used for archiving purposes, but it is possible that it will not work if the users keyboard is changed, ie between machines.
@param propertyList A property list object
@result A initialized <tt>NDHotKeyEvent</tt>
*/
+ (id)hotKeyWithWithPropertyList:(id)propertyList;
/*!
@method initWithKeyCode:character:modifierFlags:target:selector:
@abstract Initialize a <tt>NDHotKeyEvent</tt> object.
@discussion Initialize the reciever with the supplied hot key combination and target object and selector, if there is already a hot key for the supplied key code and modifer flags then nil is returned.
@param keyCode The key code used by the keyboard, can vary across hardware.
@param aChar The character, used for display purposes only.
@param modifierFlags The modifer flags, ( <tt>NSCommandKeyMask</tt>, <tt>NSControlKeyMask</tt>, <tt>NSAlternateKeyMask</tt>, <tt>NSShiftKeyMask</tt> ).
@param target The target of hot key event.
@param selector The selector sent when hot key is released
@result A initialized <tt>NDHotKeyEvent</tt>
*/
- (id)initWithKeyCode:(unsigned short)keyCode character:(unichar)aChar modifierFlags:(unsigned int)modifer target:(id)target selector:(SEL)selector;
/*!
@method initWithKeyCode:character:modifierFlags
@abstract Initialize a <tt>NDHotKeyEvent</tt> object.
@discussion Initialize the reciever with the supplied hot key combination, if there is already a hot key for the supplied key code and modifer flags then nil is returned.
@param keyCode The key code used by the keyboard, can vary across hardware.
@param aChar The character, used for display purposes only.
@param modifierFlags The modifer flags, ( <tt>NSCommandKeyMask</tt>, <tt>NSControlKeyMask</tt>, <tt>NSAlternateKeyMask</tt>, <tt>NSShiftKeyMask</tt> ).
@result A initialized <tt>NDHotKeyEvent</tt>
*/
- (id)initWithKeyCode:(unsigned short)keyCode character:(unichar)aChar modifierFlags:(unsigned int)modifer;
/*!
@method initWithPropertyList:
@abstract Initializes the reciever with a property list.
@discussion This can be used for archiving purposes, but it is possible that it will not work if the users keyboard is changed, ie between machines. The following properties are initialised
<ul>
<li>Key Code</li>
<li>Character</li>
<li>Modifier Flags</li>
<li>Selector Pressed</li>
<li>Selector Released</li>
</ul>
@param propertyList A property list object
@result A initialized <tt>NDHotKeyEvent</tt>
*/
- (id)initWithPropertyList:(id)propertyList;
/*!
@method propertyList
@abstract Returns a property list for the reciever.
@discussion This can be used for archiving purposes, but it is possible that it will not work if the users keyboard is changed, ie between machines. The property list returned contains the following properties;
<ul>
<li>Key Code</li>
<li>Character</li>
<li>Modifier Flags</li>
<li>Selector Pressed</li>
<li>Selector Released</li>
</ul>
@result The property list object.
*/
- (id)propertyList;
/*!
@method initWithCoder:
@abstract Initializes a newly allocated instance from data in <tt>decoder</tt>.
@discussion Decodes the following properties of a <tt>NDHotKeyEvent</tt>;
<ul>
<li>Key Code</li>
<li>Character</li>
<li>Modifier Flags</li>
<li>Selector Pressed</li>
<li>Selector Released</li>
</ul>
Will use Keyed Coding if <code>[<i>decoder</i> allowsKeyedCoding] == YES</code>.
@param decoder A subclass of <tt>NSCoder</tt>
@result A initialized <tt>NDHotKeyEvent</tt>
*/
- (id)initWithCoder:(NSCoder *)decoder;
/*!
@method encodeWithCoder:
@abstract Encodes the receiver using <tt>encoder</tt>
@discussion Encodes the following properties of a <tt>NDHotKeyEvent</tt>;
<ul>
<li>Key Code</li>
<li>Character</li>
<li>Modifier Flags</li>
<li>Selector Pressed</li>
<li>Selector Released</li>
</ul>
Will use Keyed Coding if <code>[<i>encoder</i> allowsKeyedCoding] == YES</code>.
@param encoder A subclass of <tt>NSCoder</tt>.
*/
- (void)encodeWithCoder:(NSCoder *)encoder;
/*!
@method setEnabled:
@abstract Set the hot key enabled or disable.
@discussion <tt>setEnabled:</tt> registers or unregisters the recievers hot key combination.
@param flag <tt>YES</tt> to enable, <tt>NO</tt> to disable.
@result Returns <tt>YES</tt> if successful
*/
- (BOOL)setEnabled:(BOOL)flag;
/*!
@method isEnabled
@abstract Find out if a hot key is enabled.
@discussion Returns <tt>YES</tt> if the hot key is registered.
@result <tt>YES</tt> if enabled.
*/
- (BOOL)isEnabled;
/*!
@method target
@abstract Get the hot key event target.
@discussion Returns the object that is sent the key pressed and key released hot key events, see the methods <tt>-selector</tt>, <tt>-selectorReleased</tt> and <tt>selectorPressed</tt>.
@result The target object.
*/
- (id)target;
/*!
@method selector
@abstract The selector for a key released event.
@discussion This is the selector sent when the hot key combination for the reciever is released. This is the same selector has returned from the method <tt>[NDHotKeyEvent selectorReleased]</tt>
@result The method selector.
*/
- (SEL)selector;
/*!
@method selectorReleased
@abstract The selector for a key released event.
@discussion This is the selector sent when the hot key combination for the reciever is released. This is the same selector has returned from the method <tt>[NDHotKeyEvent selector]</tt>
@result The method selector.
*/
- (SEL)selectorReleased;
/*!
@method selectorPressed
@abstract The selector for a key pressed event.
@discussion This is the selector sent when the hot key combination for the reciever is pressed.
@result The method selector.
*/
- (SEL)selectorPressed;
/*!
@method currentEventType
@abstract Get the current hot key event type.
@discussion This value returns what event last occured. Can be used in your target when it is sent a event message to find out what event occured, possible values are
<blockquote>
<table border = "1" width = "90%">
<thead><tr><th>Value</th><th>Description</th></tr></thead>
<tr><td align = "center"><tt>NDHotKeyNoEvent</tt></td><td>The hot key has not been pressed yet.</td></tr>
<tr><td align = "center"><tt>NDHotKeyPressedEvent</tt></td><td>The hot key was pressed last.</td></tr>
<tr><td align = "center"><tt>NDHotKeyReleasedEvent</tt></td><td>The hot key was released last.</td></tr>
</table>
</blockquote>
@result The last event type.
*/
- (int)currentEventType;
/*!
@method setTarget:selector:
@abstract Set the hot key target.
@discussion Set the target object and selector to be sent when the hot key is released.
@param target The traget object.
@param selector The selector.
@result returns <tt>YES</tt> if successful.
*/
- (BOOL)setTarget:(id)target selector:(SEL)selector;
/*!
@method setTarget:selectorReleased:selectorPressed:
@abstract Set the hot key target.
@discussion Set the target object and selector to be sent when the hot key is pressed and wehn it is released.
@param target The traget object.
@param selectorReleased The key released selector.
@param selectorPressed The key pressed selector.
@result returns <tt>YES</tt> if successful.
*/
- (BOOL)setTarget:(id)target selectorReleased:(SEL)selectorReleased selectorPressed:(SEL)selectorPressed;
/*!
@method performHotKeyReleased
@abstract Invoke the target with the release selector.
@discussion Use to send the selector for a release event, though this method can be called by you.
*/
- (void)performHotKeyReleased;
/*!
@method performHotKeyPressed
@abstract Invoke the target with the press selector.
@discussion Use to send the selector for a presse event, though this method can be called by you.
*/
- (void)performHotKeyPressed;
/*!
@method keyCode
@abstract Get the hot key key code.
@discussion The key code for the hot key, this is hardware specific.
@result The key code.
*/
- (unsigned short)keyCode;
/*!
@method character
@abstract Get the hot key character.
@discussion This is the character for the key code, without modifier keys. The character is for display purposes only and dose not determine the key code.
@result A uni code character.
*/
- (unichar)character;
/*!
@method modifierFlags
@abstract Get the hot key modifer key flags.
@discussion The <tt>modifierFlags</tt> can be a bitwise and combination of <tt>NSControlKeyMask</tt>, <tt>NSAlternateKeyMask</tt>, <tt>NSShiftKeyMask</tt>, and <tt>NSCommandKeyMask</tt>.
@result The modifer key flags.
*/
- (unsigned int)modifierFlags;
/*!
@method stringValue
@abstract Get a string got the hot keys.
@discussion This is a string that can be used for display purposes.
@result A <tt>NSString</tt>
*/
- (NSString *)stringValue;
@end
/*!
@protocol NSObject(NDHotKeyEventTragetWillChange)
@abstract Informal protocol used to inform a <tt>NDHotKeyEvent</tt> target of events.
@discussion The informal protocol <tt>NDHotKeyEventTragetWillChange</tt> defines a method used to notify a <tt>NDHotKeyEvent</tt> target that the target will change.
*/
@interface NSObject (NDHotKeyEventTragetWillChange)
/*!
@method targetWillChangeToObject:forHotKeyEvent:
@abstract Message sent to a target object to inform it that the target is going to change.
@discussion This method can be used to notify the receiver that it will no longer be the target for a <tt>NDHotKeyEvent</tt> or used to prevent the target from changing by returning <tt>NO</tt>
@param target The new target for the <tt>NDHotKeyEvent</tt>
@param hotKeyEvent The <tt>NDHotKeyEvent</tt> for which the target is changing.
@result Return <tt>NO</tt> to prevent the target from changing, otherwise return <tt>YES</tt>.
*/
- (BOOL)targetWillChangeToObject:(id)target forHotKeyEvent:(NDHotKeyEvent *)hotKeyEvent;
@end
/*!
@function stringForKeyCodeAndModifierFlags
@abstract Get a string for hot key parameters.
@discussion Returns a string representation of the passed in hot key values.
@param keyCode A key code.
@param aChar A character representation of the key code.
@param modifierFlags modifer flags, comman, option, shift and control.
@result A <tt>NSString</tt> representing the hot key combination.
*/
NSString * stringForKeyCodeAndModifierFlags( unsigned short keyCode, unichar aChar, unsigned int modifierFlags );
/*!
@function unicharForKeyCode
@abstract Get a unicode charater for the key combination.
@discussion The uncode chararter for the key combination.
@param keyCode The key code used by the keyboard, can vary across hardware.
@result A <tt>unichar</tt>
*/
unichar unicharForKeyCode( unsigned short keyCode );

File diff suppressed because it is too large Load Diff

View File

@ -1,76 +0,0 @@
/*!
@header NDHotKeyControl.h
@abstract Header file for a subclass of NSTextField for getting hot key combinations from the user.
@discussion The <tt>NDHotKeyControl</tt> can be used to get a <tt>NDHotKeyEvent</tt> for the last key combination pressed by the user.
Created by Nathan Day on Wed Mar 05 2003.
Copyright (c) 2002 Nathan Day. All rights reserved.
*/
#import <AppKit/AppKit.h>
@class NDHotKeyEvent;
/*!
@class NDHotKeyControl
@abstract Subclass of NSTextField for getting hot key combinations from the user.
@discussion The <tt>NDHotKeyControl</tt> can be used to get a <tt>NDHotKeyEvent</tt> for the last key combination pressed by the user.
*/
@interface NDHotKeyControl : NSTextField
{
@private
unsigned short keyCode;
unichar character;
unsigned long modifierFlags;
BOOL requiresModifierKeys;
}
/*!
@method keyCode
@abstract Get key code.
@discussion Returns the key code for the last key combination the user pressed while the reciever was active.
@result A <tt>unsigned short</tt> containing key code.
*/
- (unsigned short)keyCode;
/*!
@method character
@abstract Get unicode character.
@discussion Returns the unicode character for the last key combination the user pressed while the reciever was active.
@result A <tt>unichar</tt> containing character.
*/
- (unichar)character;
/*!
@method modifierFlags
@abstract Get modifer flags.
@discussion Returns the modifer flags for the last key combination the user pressed while the reciever was active.
@result A <tt>unsigned long</tt> containing modifer flags.
*/
- (unsigned long)modifierFlags;
/*!
@method hotKeyEvent
@abstract Get <tt>NDHotKeyEvent</tt>
@discussion Returns the <tt>NDHotKeyEvent</tt> instance for the last key combination the user pressed while the reciever was active. The <tt>NDHotKeyEvent</tt> returned will either be one that has already been created or a newly created one otherwise.
@result A <tt>NDHotKeyEvent</tt> for the hot key event.
*/
- (NDHotKeyEvent *)hotKeyEvent;
/*!
@method setRequiresModifierKeys:
@abstract Set whether hot keys entered need modifiers keys.
@discussion This does not include function key which do not require modifier keys no matter what the value you pass for the argument <tt><i>flag</i></tt>
@param flag If <tt>NO</tt> then the reciever only accepts hot keys combination containing modifer keys.
*/
- (void)setRequiresModifierKeys:(BOOL)flag;
/*!
@method requiresModifierKeys
@abstract Returns whether hot keys entered need modifiers keys.
@discussion This does not include key which do not require modifier keys no matter what the value is returned.
@result If <tt>NO</tt> then the reciever only accepts hot keys combination containing modifer keys.
*/
- (BOOL)requiresModifierKeys;
@end

View File

@ -1,116 +0,0 @@
/*
* NDHotKeyControl.m
* NDHotKeyEvent
*
* Created by Nathan Day on Wed Mar 05 2003.
* Copyright (c) 2002 Nathan Day. All rights reserved.
*/
#import "NDHotKeyControl.h"
#import "NDHotKeyEvent.h"
/*
* class implementation NDHotKeyControl
*/
@implementation NDHotKeyControl
/*
* -initWithFrame:
*/
- (id)initWithFrame:(NSRect)aFrame
{
if ( self = [super initWithFrame:aFrame] )
{
[self setEditable:NO];
requiresModifierKeys = YES;
}
return self;
}
/*
* -initWithCoder:
*/
- (id)initWithCoder:(NSCoder *)aCoder
{
if ( self = [super initWithCoder:aCoder] )
{
[self setEditable:NO];
requiresModifierKeys = YES;
}
return self;
}
/*
* -keyCode
*/
- (unsigned short)keyCode
{
return keyCode;
}
/*
* -character
*/
- (unichar)character
{
return character;
}
/*
* -modifierFlags
*/
- (unsigned long)modifierFlags
{
return modifierFlags;
}
/*
* -performKeyEquivalent:
*/
- (BOOL)performKeyEquivalent:(NSEvent*)anEvent
{
[self keyDown:anEvent];
return YES;
}
/*
* -keyDown:
*/
- (void)keyDown:(NSEvent *)theEvent
{
unsigned long theModifierFlags = [theEvent modifierFlags];
unichar theChar = [[theEvent charactersIgnoringModifiers] characterAtIndex:0];
theModifierFlags &= (NSShiftKeyMask|NSControlKeyMask|NSAlternateKeyMask|NSCommandKeyMask);
if( (theModifierFlags != 0 || !requiresModifierKeys || theChar > 255) && theChar != 0 )
{
keyCode = [theEvent keyCode];
modifierFlags = theModifierFlags;
character = theChar;
[self setStringValue:stringForKeyCodeAndModifierFlags( keyCode, character, modifierFlags )];
[self performClick:self];
}
}
/*
* -hotKeyEvent
*/
- (NDHotKeyEvent *)hotKeyEvent
{
return [NDHotKeyEvent getHotKeyForKeyCode:[self keyCode] character:[self character] modifierFlags:[self modifierFlags]];
}
- (void)setRequiresModifierKeys:(BOOL)aFlag
{
requiresModifierKeys = aFlag;
}
- (BOOL)requiresModifierKeys
{
return requiresModifierKeys;
}
@end

File diff suppressed because it is too large Load Diff