Observatory is a micro-framework for easier event, notification and hotkey management in Swift.
Observe global hotkeys.
let observer: HotkeyObserver = HotkeyObserver(active: true)
let fooHotkey: KeyboardHotkey = KeyboardHotkey(key: KeyboardKey.five, modifier: [.commandKey, .shiftKey])
let barHotkey: KeyboardHotkey = KeyboardHotkey(key: KeyboardKey.six, modifier: [.commandKey, .shiftKey])
observer
.add(hotkey: fooHotkey) { Swift.print("Such fooβ¦") }
.add(hotkey: barHotkey) { Swift.print("So barβ¦") }
Observe notifications, chose between plain () -> ()
or standard (Notification) -> ()
signatures.
let observer: NotificationObserver = NotificationObserver(active: true)
let observee: AnyObject = NSObject()
observer
.add(name: Notification.Name("foo"), observee: observee) { Swift.print("Foo captain!") }
.add(names: [Notification.Name("bar"), Notification.Name("baz")], observee: observee) { Swift.print("Yes \($0.name)!") }
Observe events, like with notifications, you can chose between plain () -> ()
and standard local (NSEvent) -> NSEvent?
or global (NSEvent) -> ()
signatures.
let observer: EventObserver = EventObserver(active: true)
observer
.add(mask: .any, handler: { Swift.print("Any is better than none.") })
.add(mask: [.leftMouseDown, .leftMouseUp], handler: { Swift.print("It's a \($0.type) event!") })
Checkout Observatory.playground
for information and examples.
link |
Stars: 12 |
Last commit: 1 year ago |
This is a breaking change release:
HotkeyCommand
and HotkeyCenter
was replaced with Shortcut
and ShortcutCenter
, see unit tests for details and examples.Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics