Simple global shortcuts in macOS
Switch branches/tags
Nothing to show
Clone or download
Latest commit 574e974 Sep 20, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Example Add SPM support Nov 22, 2017
HotKey.xcodeproj Update Xcode project Sep 20, 2018
Sources/HotKey Unregister HotKeys on pause Sep 20, 2018
Support Version 0.1.1 Sep 20, 2018
Tests/HotKeyTests Add SPM support Nov 22, 2017
.gitignore Ignore zip files Nov 23, 2017
.swift-version Swift 4.2 Sep 20, 2018
.travis.yml Add SPM support Nov 22, 2017
HotKey.podspec Swift 4.2 Sep 20, 2018
LICENSE Add license and readme Jul 21, 2017
Package.swift Swift 4.2 Sep 20, 2018
README.md Update readme Sep 20, 2018

README.md

HotKey

Version Build Status Swift Version Carthage compatible CocoaPods compatible

Simple global shortcuts in macOS. HotKey wraps the Carbon APIs for dealing with global hot keys to make it easy to use in Swift.

HotKey, along with Color, were created for use in Contrast, a macOS app for checking designs for accessible color combinations.

Installation

Carthage

For installation with Carthage, simply add the following to your Cartfile:

github "soffes/HotKey"

Swift Package Manager

For installation with Swift Package Manager, simply add the following to your Package.swift:

.package(url: "https://github.com/soffes/HotKey", from: "0.1.0")

CocoaPods

For installation with CocoaPods, simply add the following to your Podfile:

pod 'HotKey'

Usage

Simply initialize a HotKey with a key and modifiers:

// Setup hot key for ⌥⌘R
let hotKey = HotKey(key: .r, modifiers: [.command, .option])

This is a convenice initializer that creates a KeyCombo for you. You can also initialize with a Carbon key code and Carbon modifier flags if you’re feeling old school.

Now you can set the keyDownHandler and get callbacks for when your hot key is pressed:

hotKey.keyDownHandler = {
  print("Pressed at \(Date())")
}

You can also implement hotKey.keyUpHandler if you’d like.

You don’t need to think about when handlers are registered and unregistered. This all happens automatically based on the HotKey object’s lifecycle.

Thanks

HotKey was heavily inspired by PTHotKey.