Install HotKey via Swift Package Manager
mainTo use HotKey in your Swift project via Swift Package Manager, add the following dependency to your Package.swift file:
.package(url: "https://github.com/soffes/HotKey", from: "0.2.1")repository·main·Indexed 22 days ago
https://github.com/soffes/hotkeyA Swift wrapper for macOS Carbon APIs that allows developers to implement global keyboard shortcuts. It provides functionality to register hot keys with modifiers and handle keyDown and keyUp events via closures.
To use HotKey in your Swift project via Swift Package Manager, add the following dependency to your Package.swift file:
.package(url: "https://github.com/soffes/HotKey", from: "0.2.1")To use HotKey in your project with CocoaPods, add the following line to your Podfile:
pod 'HotKey'To use HotKey in your project with Carthage, add the following line to your Cartfile:
github "soffes/HotKey"Initialize a HotKey object by specifying a key and a set of modifiers. The library provides a convenience initializer that accepts a key and an array of modifiers (e.g., .command, .option, .shift, .control).
Registration and unregistration of the hot key are handled automatically based on the lifecycle of the HotKey instance.
// Setup hot key for ⌥⌘R
let hotKey = HotKey(key: .r, modifiers: [.command, .option])Once a HotKey is initialized, you can assign closures to keyDownHandler and keyUpHandler to respond to user input. The keyDownHandler is triggered when the specified key combination is pressed.
hotKey.keyDownHandler = {
print("Pressed at \(Date())")
}
// You can also implement keyUpHandler
hotKey.keyUpHandler = {
print("Released")
}