explaingit

sindresorhus/keyboardshortcuts

Analysis updated 2026-05-18

2,630SwiftAudience · developerComplexity · 2/5Setup · easy

TLDR

A Swift package that lets macOS apps offer user-customizable global keyboard shortcuts, complete with a settings recorder component.

Mindmap

mindmap
  root((KeyboardShortcuts))
    What it does
      Global hotkeys
      Shortcut recorder UI
      Conflict detection
    Tech stack
      Swift
      SwiftUI
      AppKit
      Carbon
    Use cases
      Menu bar app shortcuts
      In app shortcuts
      Settings screens
    Audience
      macOS developers

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Let users set their own global keyboard shortcut for a menu bar utility.

USE CASE 2

Add a shortcut recorder to a macOS app's settings screen with automatic conflict warnings.

USE CASE 3

Support in-app-only shortcuts that fire without registering a global hotkey.

USE CASE 4

Persist a user's chosen shortcut automatically across app restarts.

What is it built with?

SwiftSwiftUIAppKitCarbonUserDefaults

How does it compare?

sindresorhus/keyboardshortcutssindresorhus/defaultsvorssaint/vorssaint-utils
Stars2,6302,4652,265
LanguageSwiftSwiftSwift
Last pushed2026-07-03
MaintenanceActive
Setup difficultyeasyeasyeasy
Complexity2/52/52/5
Audiencedeveloperdevelopergeneral

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 30min

In plain English

KeyboardShortcuts is a Swift package for macOS app developers who want to let users set their own global keyboard shortcuts inside the app's settings screen. A global keyboard shortcut is one that works even when the app is not the active window, which is common in menu bar utilities and productivity tools. Without a library like this, adding user-customizable global shortcuts in a macOS app requires writing a fair amount of boilerplate code dealing with low-level system APIs. This package reduces that to a few lines: you give a shortcut a name in code, drop a recorder component into your settings view, and add a listener that runs code when the user presses their chosen shortcut. The recorder component also detects conflicts with existing system shortcuts and warns the user. The package saves each shortcut to UserDefaults automatically, so the user's choice is remembered across app restarts. It supports both SwiftUI and the older Cocoa (AppKit) UI frameworks. You can listen for a key being pressed down or released, or set up repeating events while the key is held. For apps that do not need global shortcuts, the package also supports in-app shortcuts that only work when the app is focused, using the same recorder component with a different configuration. The package is sandboxed and compatible with the Mac App Store. Internally it uses some older Carbon APIs for the global hotkey registration because Apple has not yet provided modern replacements for that specific capability, but the author notes this should not be a concern for app developers using the package. It is distributed as a Swift Package and requires macOS 10.15 or later.

Copy-paste prompts

Prompt 1
Show me how to add the KeyboardShortcuts package and register a named global shortcut in my macOS app.
Prompt 2
Help me add a KeyboardShortcuts.Recorder to my SwiftUI settings screen.
Prompt 3
Explain how to listen for a global keyboard shortcut key-down event using this package.
Prompt 4
How do I set up an in-app-only keyboard shortcut instead of a global one with KeyboardShortcuts?

Frequently asked questions

What is keyboardshortcuts?

A Swift package that lets macOS apps offer user-customizable global keyboard shortcuts, complete with a settings recorder component.

What language is keyboardshortcuts written in?

Mainly Swift. The stack also includes Swift, SwiftUI, AppKit.

How hard is keyboardshortcuts to set up?

Setup difficulty is rated easy, with roughly 30min to a first successful run.

Who is keyboardshortcuts for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.