Skip to content
This repository was archived by the owner on Mar 11, 2024. It is now read-only.

Commit f385dd9

Browse files
committed
README.markdown
1 parent 87d20d6 commit f385dd9

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

DDHotKey/README.markdown

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# DDHotKey
2+
3+
Copyright &copy; Dave DeLong <http://www.davedelong.com>
4+
5+
## About
6+
7+
DDHotKey is an easy-to-use Cocoa class for registering an application to respond to system key events, or "hotkeys".
8+
9+
A global hotkey is a key combination that always executes a specific action, regardless of which app is frontmost. For example, the Mac OS X default hotkey of "command-space" shows the Spotlight search bar, even if Finder is not the frontmost application.
10+
11+
## License
12+
13+
The license for this framework is included in every source file, and is repoduced in its entirety here:
14+
15+
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 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.
16+
17+
## Usage
18+
19+
### Including DDHotKey in your project
20+
21+
You will need to copy these six files into your project:
22+
23+
- DDHotKeyCenter.h
24+
- DDHotKeyCenter.m
25+
- DDHotKeyUtilities.h
26+
- DDHotKeyUtilities.m
27+
- DDHotKeyTextField.h
28+
- DDHotKeyTextField.m
29+
30+
Your application will need to link against `Carbon.framework`, and you will need to compile your application with the Clang compiler. DDHotKey has been tested with Xcode 5 on OS X Mavericks. No attempt has been made to preserve backwards compatibility.
31+
32+
### Using DDHotKey in your code
33+
34+
When you wish to create a hotkey, you'll need to do so via the `DDHotKeyCenter` singleton.
35+
36+
You can register a hotkey in one of two ways: via a target/action mechanism, or with a block. The target/action mechanism can take a single extra "object" parameter, which it will pass into the action when the hotkey is fired. Only the `object` parameter is retained by the `DDHotKeyCenter`. In addition, an `NSEvent` object is passed, which contains information regarding the hotkey event (such as the location, the keyCode, the modifierFlags, etc).
37+
38+
Hotkey actions must have one of two method signatures (the actual selector is irrelevant):
39+
40+
//a method with a single NSEvent parameter
41+
- (void)hotkeyAction:(NSEvent*)hotKeyEvent;
42+
43+
OR
44+
45+
//a method with an NSEvent parameter and an object parameter
46+
- (void)hotkeyAction:(NSEvent*)hotKeyEvent withObject:(id)anObject;
47+
48+
The other way to register a hotkey is with a block callback. The block must have the following signature:
49+
50+
void (^)(NSEvent *);
51+
52+
`DDHotKeyCenter.h` contains a typedef statement to typedef this signature as a `DDHotKeyTask`, for convenience.
53+
54+
Any hotkey that you have registered via `DDHotKeyCenter` can be unregistered based on its target, its target and action, or its keycode and modifier flags.
55+
56+
DDHotKey also includes a rudimentary `DDHotKeyTextField`, which is an `NSTextField` subclass that simplifies the process of creating a key combination. Simply drop an `NSTextField` into your xib and change its class to `DDHotKeyTextField`. Programmatically, you'll get an NSTextField into which you can type arbitrary key combinations. You access the resulting combination via the textfield's `hotKey` property.

0 commit comments

Comments
 (0)