Skip to content
forked from soffes/HotKey

Simple global shortcuts in macOS

License

Notifications You must be signed in to change notification settings

imraghava/HotKey

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HotKey

Version Swift Version Carthage 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.

Usage

Simply initlaize 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.

About

Simple global shortcuts in macOS

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 98.6%
  • Objective-C 1.4%