{"id":13468090,"url":"https://github.com/jordanbaird/SwiftKeys","last_synced_at":"2025-03-26T03:31:33.508Z","repository":{"id":39660270,"uuid":"487154806","full_name":"jordanbaird/SwiftKeys","owner":"jordanbaird","description":"Global macOS key commands","archived":false,"fork":false,"pushed_at":"2023-12-19T21:37:33.000Z","size":2200,"stargazers_count":47,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-07T22:17:24.198Z","etag":null,"topics":["hotkey","hotkeys","key-command","key-commands","keyboard","keyboard-shortcut","keyboard-shortcuts","macos","shortcut","shortcuts","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jordanbaird.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"jordanbaird","buy_me_a_coffee":"jordanbaird"}},"created_at":"2022-04-30T01:35:52.000Z","updated_at":"2024-12-27T08:26:46.000Z","dependencies_parsed_at":"2024-10-24T15:29:20.927Z","dependency_job_id":"7df1d6f5-940d-413f-b897-0b7d786f3d0e","html_url":"https://github.com/jordanbaird/SwiftKeys","commit_stats":{"total_commits":204,"total_committers":4,"mean_commits":51.0,"dds":0.4558823529411765,"last_synced_commit":"9f293e1ab25513a34d274b3a5ea81eeee4f47090"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jordanbaird%2FSwiftKeys","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jordanbaird%2FSwiftKeys/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jordanbaird%2FSwiftKeys/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jordanbaird%2FSwiftKeys/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jordanbaird","download_url":"https://codeload.github.com/jordanbaird/SwiftKeys/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245584959,"owners_count":20639653,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hotkey","hotkeys","key-command","key-commands","keyboard","keyboard-shortcut","keyboard-shortcuts","macos","shortcut","shortcuts","swift"],"created_at":"2024-07-31T15:01:05.395Z","updated_at":"2025-03-26T03:31:32.923Z","avatar_url":"https://github.com/jordanbaird.png","language":"Swift","funding_links":["https://github.com/sponsors/jordanbaird","https://buymeacoffee.com/jordanbaird"],"categories":["Swift"],"sub_categories":[],"readme":"\u003ch1 align='center'\u003e\n    \u003cbr\u003e\n    \u003cimg src='Sources/SwiftKeys/Documentation.docc/Resources/header.png', style='width:67%'\u003e\n    \u003cbr\u003e\n    Global macOS key commands\n    \u003cbr\u003e\n    \u003cbr\u003e\n\u003c/h1\u003e\n\n[![Continuous Integration][ci-badge]](https://github.com/jordanbaird/SwiftKeys/actions/workflows/test.yml)\n[![Release][release-badge]](https://github.com/jordanbaird/SwiftKeys/releases/latest)\n[![Swift Versions][versions-badge]](https://swiftpackageindex.com/jordanbaird/SwiftKeys)\n[![Docs][docs-badge]](https://swiftpackageindex.com/jordanbaird/SwiftKeys/documentation)\n[![License][license-badge]](LICENSE)\n\n## Install\n\nAdd the following dependency to your `Package.swift` file:\n\n```swift\n.package(url: \"https://github.com/jordanbaird/SwiftKeys\", from: \"0.2.0\")\n```\n\n## Usage\n\n[Read the full documentation here](https://swiftpackageindex.com/jordanbaird/SwiftKeys/documentation)\n\n### Creating and Observing\n\nStart by creating an instance of `KeyCommand`. Observe it, and perform actions on `keyDown`, `keyUp`, and `doubleTap(_:)`:\n\n```swift\nlet command = KeyCommand(name: \"ToggleMainWindow\")\n\ncommand.observe(.keyDown) {\n    myCustomKeyDownAction()\n}\n\ncommand.observe(.keyUp) {\n    myCustomKeyUpAction()\n}\n\ncommand.observe(.doubleTap(0.2)) {\n    myCustomDoubleTapAction()\n}\n```\n\n\u003e `doubleTap(_:)` allows you to specify a maximum time interval that the two key presses must fall within to be considered a \"double-tap\".\n\n### Adding a Key Recorder\n\nUse the key command's name to create a key recorder. Then, add it to a view (note the use of `KeyRecorderView` for SwiftUI and `KeyRecorder` for Cocoa):\n\n#### SwiftUI\n\n```swift\nstruct SettingsView: View {\n    var body: some View {\n        KeyRecorderView(name: \"ToggleMainWindow\")\n    }\n}\n```\n\n#### Cocoa\n\n```swift\nclass SettingsViewController: NSViewController {\n    let recorder = KeyRecorder(name: \"ToggleMainWindow\")\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n        view.addSubview(recorder)\n    }\n}\n```\n\nThe result should look something like this:\n\n| Light mode           | Dark mode                 |\n| -------------------- | ------------------------- |\n| ![][recorder-window] | ![][recorder-window~dark] |\n\nThe recorder and command will stay synchronized with each other, so when the user records a new key combination, the command will be updated to match the new value.\n\n---\n\nFor improved type safety, you can create hard-coded command names that can be referenced across your app.\n\n`Misc.swift`\n```swift\nextension KeyCommand.Name {\n    static let toggleMainWindow = Self(\"ToggleMainWindow\")\n}\n```\n\n`AppDelegate.swift`\n```swift\nlet command = KeyCommand(name: .toggleMainWindow)\n```\n\n`SettingsView.swift`\n```swift\nlet recorder = KeyRecorder(name: .toggleMainWindow)\n```\n\n---\n\nKey commands are automatically stored in the `UserDefaults` system, using their names as keys. It's common for `UserDefaults` keys to be prefixed, or namespaced, according to their corresponding app or subsystem. To that end, SwiftKeys lets you provide custom prefixes that can be applied to individual names.\n\n```swift\nextension KeyCommand.Name.Prefix {\n    static let settings = Self(\"Settings\")\n    static let app = Self(\"MyGreatApp\")\n}\n\nextension KeyCommand.Name {\n    // \"SettingsOpen\" will be the full UserDefaults key.\n    static let openSettings = Self(\"Open\", prefix: .settings)\n    \n    // \"MyGreatApp_Quit\" will be the full UserDefaults key.\n    static let quitApp = Self(\"Quit\", prefix: .app, separator: \"_\")\n}\n```\n\n## License\n\nSwiftKeys is available under the [MIT license](LICENSE).\n\n[recorder-window]: Sources/SwiftKeys/Documentation.docc/Resources/recorder-window.png\n[recorder-window~dark]: Sources/SwiftKeys/Documentation.docc/Resources/recorder-window~dark.png\n\n[ci-badge]: https://img.shields.io/github/actions/workflow/status/jordanbaird/SwiftKeys/test.yml?branch=main\u0026style=flat-square\n[release-badge]: https://img.shields.io/github/v/release/jordanbaird/SwiftKeys?style=flat-square\n[versions-badge]: https://img.shields.io/badge/dynamic/json?color=F05138\u0026label=Swift\u0026query=%24.message\u0026url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fjordanbaird%2FSwiftKeys%2Fbadge%3Ftype%3Dswift-versions\u0026style=flat-square\n[docs-badge]: https://img.shields.io/static/v1?label=%20\u0026message=documentation\u0026logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAEsSURBVHgB7dntDYIwEAbgV+MAuoEj6AaO4AiO4AayAbqBbuAGjoIbwAbnHT8MMTH9uEJrvCch/FB7vEh7EABjjBMRnXhrKY1GxsNUuFhN45gmBKU783lCDKtBiYeoUoeYI79KE6KEACI6RCkBRFSIkgKI4BClBRBBIUoMILxDlBpASIgjtBL3gR2FaV1jzjyKvg98xqDEw615t3Z87eFbc/IAPkJqljwHvFiA3CxAbhaAdI+cNZTUfWD4edQBOMacog9cEE/z25514twsQG4/H2ABJZ5vG97tEefKc/QJhRR9oIH7AeWbjodchdYcSnEJLRGvg5L6EmJb3g6Ic4eSNbLcLEBuf9HIZKnrl0rtvX8E5zLr8w+o79kVbkiBT/yZxn3Z90lqVTDGOL0AoGWIIaQgyakAAAAASUVORK5CYII=\u0026color=informational\u0026labelColor=gray\u0026style=flat-square\n[license-badge]: https://img.shields.io/github/license/jordanbaird/SwiftKeys?style=flat-square\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjordanbaird%2FSwiftKeys","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjordanbaird%2FSwiftKeys","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjordanbaird%2FSwiftKeys/lists"}