A Swifty API for global macOS hotkeys.

Overview

A Swifty API for global macOS hotkeys.


Continuous Integration Code Coverage Release Swift Version License

Install

Add the following dependency to your Package.swift file:

.package(url: "https://github.com/jordanbaird/SwiftKeys", from: "0.0.5")

Usage

Read the full documentation here

Start by creating an instance of KeyEvent. Then, use it to initialize a KeyRecorder.

let event = KeyEvent(name: "SomeEvent")
let recorder = KeyRecorder(keyEvent: event)

The recorder and the event will stay synchronized with each other, so when the user records a new key combination, the event will update to the new value. You can also observe the event and perform actions on both key-up and key-down.

event.observe(.keyUp) {
    print("UP")
}
event.observe(.keyDown) {
    print("DOWN")
}

For improved type safety, you can create hard-coded key event names that can be referenced across your app.

extension KeyEvent.Name {
    static let showPreferences = Self("ShowPreferences")
}
let event = KeyEvent(name: .showPreferences)

Key events are automatically stored in the UserDefaults system, using their names as keys. You can provide a custom prefix that will be combined with each name to create the keys.

extension KeyEvent.Name.Prefix {
    public override var sharedPrefix: Self { 
        Self("SK")
    }
}

In the example above, the name "ShowPreferences" would become "SKShowPreferences" when used as a defaults key.

The following pseudo-code is what a typical view controller that utilizes SwiftKeys might look like:

import SwiftKeys

class ViewController: NSViewController {
    let event = KeyEvent(name: "SomeEvent")
    let recorder = KeyRecorder(keyEvent: event)
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.addSubview(recorder)
        
        event.observe(.keyUp) {
            print("UP")
        }
        event.observe(.keyDown) {
            print("DOWN")
        }
    }
}

License

SwiftKeys is licensed under the MIT license.

You might also like...
macOS WeChat.app header files version history (automatic updated)

macos-wechat-app-tracker macOS WeChat.app header files version history (automatic updated) Troubleshooting $ class-dump -H /Applications/WeChat.app 20

Natural - A macOS quick link finder
Natural - A macOS quick link finder

natural a macOS quick link finder just a fun side project based on uiw.tf – chec

macOS Sqlite tableView 샘플 - objective c

목적 Objective C언어를 이용하여 macOS를 개발해본다. Sqlite를 이용하여 데이터를 저장하고, 불러와본다. FMDB를 이용한다. 데이터를 NSTableView를 이용하여 불러와본다. 추가적으로 NSOutlineView 구현해본다. 추가적으로 KVOCont

MySQL driver for Swift 3 (macOS and Linux)

MySQL MySQL Usage // do your magic Installation import PackageDescription let package = Package( dependencies: [ .Package(url: "https://g

Link - a macos application for keeping important and complicated urls in one place
Link - a macos application for keeping important and complicated urls in one place

Link Description Link is a macos application for keeping important and complicat

A external macos application to generate and execute tuist commands
A external macos application to generate and execute tuist commands

Tuist Menu Bar App An external macos application to generate and execute tuist commands. How it works? Parses all tasks and their arguments with the -

macOS App for App Store Connect to Improve Processing Efficiency and Enjoy the Party.
macOS App for App Store Connect to Improve Processing Efficiency and Enjoy the Party.

Apple Party(苹果派) 一、App 介绍 AppleParty 是三七互娱旗下37手游 iOS 团队研发,实现快速操作 App Store Connect 后台的自动化 macOS 工具。 使用和原理介绍:开源一款苹果 macOS 工具 - AppleParty(苹果派) 支持功能 内购买

The hassle-free way to add Segment analytics to your Swift app (iOS/tvOS/watchOS/macOS/Linux).

Analytics-Swift The hassle-free way to add Segment analytics to your Swift app (iOS/tvOS/watchOS/macOS/Linux/iPadOS). Analytics helps you measure your

This plugin defines a global navigator.camera object, which provides an API for taking pictures and for choosing images from the system's image library.

title description Camera Take pictures with the device camera. AppVeyor Travis CI cordova-plugin-camera This plugin defines a global navigator.camera

Swifty Date & Time API inspired from Java 8 DateTime API.

AnyDate Swifty Date & Time API inspired from Java 8 DateTime API. Background I think that date & time API should be easy and accurate. Previous dates,

Swifty Date & Time API inspired from Java 8 DateTime API.

AnyDate Swifty Date & Time API inspired from Java 8 DateTime API. Background I think that date & time API should be easy and accurate. Previous dates,

⌨️ Add user-customizable global keyboard shortcuts to your macOS app in minutes
⌨️ Add user-customizable global keyboard shortcuts to your macOS app in minutes

This package lets you add support for user-customizable global keyboard shortcuts to your macOS app in minutes. It's fully sandbox and Mac App Store c

iOS utility class to manage global dispatch queue.
iOS utility class to manage global dispatch queue.

YYDispatchQueuePool iOS utility class to manage global dispatch queue. (It's a component of YYKit) When use a concurrent queue to execute lots of bloc

This is an Instagram clone with a custom Parse backend that allows a user to post photos, view a global photos feed, and add comments!
This is an Instagram clone with a custom Parse backend that allows a user to post photos, view a global photos feed, and add comments!

Parstagram - Part II This is an Instagram clone with a custom Parse backend that allows a user to post photos, view a global photos feed, and add comm

Condense string literals into global variables.

Gettysburg This is an implementation of the SAX interface. API Documentation Documentation of the API can be found here: Gettysburg API A note on Char

Global formula editor with swift

Koshiki (With auto-completion of Typinator. )

Commonly available global error type packages

ErrorKit 일반적으로 사용 할 수 있는 전역 오류 타입 패키지. Requirements Xcode 13.2.1+ Swift 5.5+ Ins

AREarthObservatory - A minimal iOS AR app that visualizes time-series changes in the global environment based on data from NASA satellites
AREarthObservatory - A minimal iOS AR app that visualizes time-series changes in the global environment based on data from NASA satellites

A minimal iOS AR app that visualizes time-series changes in the global environment based on data from NASA satellites

A computer-vision-driven app for detecting and mapping smog in public roads. Crowdsourcing is rewarded with NFTs. Uber Global Hackathon.
A computer-vision-driven app for detecting and mapping smog in public roads. Crowdsourcing is rewarded with NFTs. Uber Global Hackathon.

Smogify Detecting smog using ML and rewarding users with NFTs About The Project app in action: https://youtu.be/awJrP-sHb_I Under the growing uncertai

Releases(0.0.8)
Owner
Jordan Baird
Jordan Baird
Modern Swift API for NSUserDefaults

SwiftyUserDefaults Modern Swift API for NSUserDefaults SwiftyUserDefaults makes user defaults enjoyable to use by combining expressive Swifty API with

Luke 4.7k Sep 23, 2022
📕A single value proxy for NSUserDefaults, with clean API.

OneStore A single value proxy for NSUserDefaults, with clean API. With OneStore… Create one proxy(an OneStore object) for each NSUserDefaults value. M

Muukii 27 May 12, 2022
A basic application that fetches crypto coin datas from CoinBase API.

HW5_ErincDokumacioglu App named Investor that fetches latest exchange rates for cryptocurrencies from CoinMarketCap Currently has some issues, mainly

Erinç Olkan Dokumacıoğlu 0 Oct 30, 2021
BucketServer - Small API with SQLite database that saves notes for an iOS appliction called Bucket list

BucketList Server-Side Small API with SQLite database that saves notes for an iO

null 0 Dec 30, 2021
Modern Swift API for NSUserDefaults

SwiftyUserDefaults Modern Swift API for NSUserDefaults SwiftyUserDefaults makes user defaults enjoyable to use by combining expressive Swifty API with

Luke 4.7k Sep 19, 2022
How to use the Zeit Online Content API with Swift 4

ZeitSuche_iOS Version 1.4.0 - September 12, 2018 This iOS app (iPhone) shows how to use the Zeit Online Content API with Swift 4. To test this app you

Bodo Schönfeld 2 Feb 10, 2022
This Project domonstrate the latest Swift on Server to create RESTFul API's connected via Database: MongoDB NoSql

Swift is a general-purpose programming language built using a modern approach to safety & performance that make it specifically suitable for Server applications. Vapor is a web framework for Swift, allowing you to write backends, web apps APIs and HTTP servers in Swift

Furqan 3 Aug 23, 2022
Simple, Strongly Typed UserDefaults for iOS, macOS and tvOS

简体中文 DefaultsKit leverages Swift 4's powerful Codable capabilities to provide a Simple and Strongly Typed wrapper on top of UserDefaults. It uses less

Nuno Dias 1.4k Sep 20, 2022
An efficient, small mobile key-value storage framework developed by WeChat. Works on Android, iOS, macOS, Windows, and POSIX.

中文版本请参看这里 MMKV is an efficient, small, easy-to-use mobile key-value storage framework used in the WeChat application. It's currently available on Andr

Tencent 15k Sep 26, 2022