summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave DeLong2010-02-24 15:23:04 -0700
committerDave DeLong2010-02-24 15:23:04 -0700
commit440f01bce0858f48df4f13333b40afaecbf1d094 (patch)
tree95974b4417bc0a8a196ac9f48ff8743a50fcae40
parent2080059c4803bdb7fc045715533ea4b33f8ee6b1 (diff)
downloadDDHotKey-440f01bce0858f48df4f13333b40afaecbf1d094.tar.bz2
Modified the order of the parameters to follow conventsion (suggested by Quinn Taylor)
-rw-r--r--DDHotKeyAppDelegate.h16
-rw-r--r--DDHotKeyAppDelegate.m22
-rw-r--r--DDHotKeyCenter.h49
-rw-r--r--DDHotKeyCenter.m22
4 files changed, 72 insertions, 37 deletions
diff --git a/DDHotKeyAppDelegate.h b/DDHotKeyAppDelegate.h
index 4b4cbac..2b775dc 100644
--- a/DDHotKeyAppDelegate.h
+++ b/DDHotKeyAppDelegate.h
@@ -1,10 +1,12 @@
-//
-// DDHotKeyAppDelegate.h
-// DDHotKey
-//
-// Created by Dave DeLong on 2/24/10.
-// Copyright 2010 Home. All rights reserved.
-//
+/*
+ DDHotKey -- DDHotKeyAppDelegate.h
+
+ Copyright (c) 2010, Dave DeLong <http://www.davedelong.com>
+
+ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
+
+ The software is provided "as is", without warranty of any kind, including all implied warranties of merchantability and fitness. In no event shall the author(s) or copyright holder(s) 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 <Cocoa/Cocoa.h>
diff --git a/DDHotKeyAppDelegate.m b/DDHotKeyAppDelegate.m
index 888bf32..0599be2 100644
--- a/DDHotKeyAppDelegate.m
+++ b/DDHotKeyAppDelegate.m
@@ -1,10 +1,12 @@
-//
-// DDHotKeyAppDelegate.m
-// DDHotKey
-//
-// Created by Dave DeLong on 2/24/10.
-// Copyright 2010 Home. All rights reserved.
-//
+/*
+ DDHotKey -- DDHotKeyAppDelegate.m
+
+ Copyright (c) 2010, Dave DeLong <http://www.davedelong.com>
+
+ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
+
+ The software is provided "as is", without warranty of any kind, including all implied warranties of merchantability and fitness. In no event shall the author(s) or copyright holder(s) 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 "DDHotKeyAppDelegate.h"
#import "DDHotKeyCenter.h"
@@ -37,7 +39,7 @@
- (IBAction) registerExample1:(id)sender {
[self addOutput:@"Attempting to register hotkey for example 1"];
DDHotKeyCenter * c = [[DDHotKeyCenter alloc] init];
- if (![c registerHotKeyWithTarget:self action:@selector(hotkeyWithEvent:) object:nil keyCode:9 modifierFlags:NSControlKeyMask]) {
+ if (![c registerHotKeyWithKeyCode:9 modifierFlags:NSControlKeyMask target:self action:@selector(hotkeyWithEvent:) object:nil]) {
[self addOutput:@"Unable to register hotkey for example 1"];
} else {
[self addOutput:@"Registered hotkey for example 1"];
@@ -48,7 +50,7 @@
- (IBAction) registerExample2:(id)sender {
[self addOutput:@"Attempting to register hotkey for example 2"];
DDHotKeyCenter * c = [[DDHotKeyCenter alloc] init];
- if (![c registerHotKeyWithTarget:self action:@selector(hotkeyWithEvent:object:) object:@"hello, world!" keyCode:9 modifierFlags:(NSControlKeyMask | NSAlternateKeyMask)]) {
+ if (![c registerHotKeyWithKeyCode:9 modifierFlags:(NSControlKeyMask | NSAlternateKeyMask) target:self action:@selector(hotkeyWithEvent:object:) object:@"hello, world!"]) {
[self addOutput:@"Unable to register hotkey for example 2"];
} else {
[self addOutput:@"Registered hotkey for example 2"];
@@ -65,7 +67,7 @@
[self addOutput:[NSString stringWithFormat:@"Hotkey event: %@", hkEvent]];
[self addOutput:[NSString stringWithFormat:@"the answer is: %d", theAnswer]];
};
- if (![c registerHotKeyWithBlock:task keyCode:9 modifierFlags:(NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask)]) {
+ if (![c registerHotKeyWithKeyCode:9 modifierFlags:(NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask) block:task]) {
[self addOutput:@"Unable to register hotkey for example 3"];
} else {
[self addOutput:@"Registered hotkey for example 3"];
diff --git a/DDHotKeyCenter.h b/DDHotKeyCenter.h
index e1cd603..25a6fbd 100644
--- a/DDHotKeyCenter.h
+++ b/DDHotKeyCenter.h
@@ -1,16 +1,19 @@
-//
-// DDHotKeyManager.h
-// EmptyAppKit
-//
-// Created by Dave DeLong on 2/20/10.
-// Copyright 2010 Home. All rights reserved.
-//
+/*
+ DDHotKey -- DDHotKeyCenter.h
+
+ Copyright (c) 2010, Dave DeLong <http://www.davedelong.com>
+
+ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
+
+ The software is provided "as is", without warranty of any kind, including all implied warranties of merchantability and fitness. In no event shall the author(s) or copyright holder(s) 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 <Cocoa/Cocoa.h>
#define BUILD_FOR_SNOWLEOPARD (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
#if BUILD_FOR_SNOWLEOPARD
+//a convenient typedef for the required signature of a hotkey block callback
typedef void (^DDHotKeyTask)(NSEvent*);
#endif
@@ -18,15 +21,41 @@ typedef void (^DDHotKeyTask)(NSEvent*);
}
-- (BOOL) registerHotKeyWithTarget:(id)target action:(SEL)action object:(id)object keyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags;
+/**
+ Register a target/action hotkey.
+ The modifierFlags must be a bitwise OR of NSCommandKeyMask, NSAlternateKeyMask, NSControlKeyMask, or NSShiftKeyMask;
+ Returns YES if the hotkey was registered; NO otherwise.
+ */
+- (BOOL) registerHotKeyWithKeyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags target:(id)target action:(SEL)action object:(id)object;
#if BUILD_FOR_SNOWLEOPARD
-- (BOOL) registerHotKeyWithBlock:(DDHotKeyTask)task keyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags;
+/**
+ Register a block callback hotkey.
+ The modifierFlags must be a bitwise OR of NSCommandKeyMask, NSAlternateKeyMask, NSControlKeyMask, or NSShiftKeyMask;
+ Returns YES if the hotkey was registered; NO otherwise.
+ */
+- (BOOL) registerHotKeyWithKeyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags block:(DDHotKeyTask)task;
#endif
+/**
+ See if a hotkey exists with the specified keycode and modifier flags.
+ NOTE: this will only check among hotkeys you have explicitly registered. This does not check all globally registered hotkeys.
+ */
- (BOOL) hasRegisteredHotKeyWithKeyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags;
+
+/**
+ Unregister all hotkeys with a specific target
+ */
- (void) unregisterHotKeysWithTarget:(id)target;
-- (void) unregisterHotKeyWithTarget:(id)target action:(SEL)action;
+
+/**
+ Unregister all hotkeys with a specific target and action
+ */
+- (void) unregisterHotKeysWithTarget:(id)target action:(SEL)action;
+
+/**
+ Unregister a hotkey with a specific keycode and modifier flags
+ */
- (void) unregisterHotKeyWithKeyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags;
@end
diff --git a/DDHotKeyCenter.m b/DDHotKeyCenter.m
index 8cd465e..b190cf9 100644
--- a/DDHotKeyCenter.m
+++ b/DDHotKeyCenter.m
@@ -1,10 +1,12 @@
-//
-// DDHotKeyManager.m
-// EmptyAppKit
-//
-// Created by Dave DeLong on 2/20/10.
-// Copyright 2010 Home. All rights reserved.
-//
+/*
+ DDHotKey -- DDHotKeyCenter.m
+
+ Copyright (c) 2010, Dave DeLong <http://www.davedelong.com>
+
+ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
+
+ The software is provided "as is", without warranty of any kind, including all implied warranties of merchantability and fitness. In no event shall the author(s) or copyright holder(s) 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 "DDHotKeyCenter.h"
#import <Carbon/Carbon.h>
@@ -132,7 +134,7 @@ NSUInteger dd_translateModifierFlags(NSUInteger flags);
}
#if BUILD_FOR_SNOWLEOPARD
-- (BOOL) registerHotKeyWithBlock:(DDHotKeyTask)task keyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags {
+- (BOOL) registerHotKeyWithKeyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags block:(DDHotKeyTask)task {
//we can't add a new hotkey if something already has this combo
if ([self hasRegisteredHotKeyWithKeyCode:keyCode modifierFlags:flags]) { return NO; }
@@ -154,7 +156,7 @@ NSUInteger dd_translateModifierFlags(NSUInteger flags);
}
#endif
-- (BOOL) registerHotKeyWithTarget:(id)target action:(SEL)action object:(id)object keyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags {
+- (BOOL) registerHotKeyWithKeyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags target:(id)target action:(SEL)action object:(id)object {
//we can't add a new hotkey if something already has this combo
if ([self hasRegisteredHotKeyWithKeyCode:keyCode modifierFlags:flags]) { return NO; }
@@ -193,7 +195,7 @@ NSUInteger dd_translateModifierFlags(NSUInteger flags);
[self unregisterHotKeysMatchingPredicate:predicate];
}
-- (void) unregisterHotKeyWithTarget:(id)target action:(SEL)action {
+- (void) unregisterHotKeysWithTarget:(id)target action:(SEL)action {
NSPredicate * predicate = [NSPredicate predicateWithFormat:@"target = %@ AND actionString = %@", target, NSStringFromSelector(action)];
[self unregisterHotKeysMatchingPredicate:predicate];
}