Skip to content

Custom global shortcuts for record and pause #1

Description

@nftechie

Context

Snapcap registers two system-wide shortcuts: ⌥⇧⌘R (start/stop) and ⌥⇧⌘P (pause/resume). They're hard-coded, so they can clash with other apps and some keyboard layouts. Settings already has a read-only "Keyboard shortcuts" section whose footer says custom shortcuts are on the roadmap.

GlobalHotKey wraps Carbon's RegisterEventHotKey, which needs no Accessibility permission. It takes a virtual key code plus Carbon modifier flags, returns nil when registration fails, and unregisters in deinit.

Where to look

  • Sources/Snapcap/App/GlobalHotKey.swift: the wrapper.
  • Sources/Snapcap/App/AppDelegate.swift: applicationDidFinishLaunching builds hotKeys with kVK_ANSI_R / kVK_ANSI_P and cmdKey | optionKey | shiftKey. makeMainMenu() hard-codes the same shortcuts on File → Start / Stop Recording and Pause / Resume Recording.
  • Sources/Snapcap/App/StatusItemController.swift: buildMenu() sets the same key equivalents.
  • Sources/Snapcap/Views/SettingsView.swift: the "Keyboard shortcuts" section (Shortcut view).
  • Hard-coded hints: RecordBar in Sources/Snapcap/Views/RecorderView.swift, the footer of Sources/Snapcap/Views/QuickRecordView.swift, and the HUDButton help strings in Sources/Snapcap/Windows/RecordingPanels.swift.

Proposal

  • Add a small Codable KeyboardShortcut-style value (key code + modifiers) that can produce its display string ("⌥⇧⌘R"), Carbon modifiers and NSEvent.ModifierFlags. Put the pure parts in SnapcapCore so they can be unit tested.
  • In Settings, replace the read-only rows with a recorder control: click it, press a combination, done. Esc cancels, and there's a "Reset to default" button. Require at least one of ⌘, ⌥ or ⌃.
  • Persist the shortcuts in UserDefaults, and re-register on change by dropping the old GlobalHotKey and creating a new one.
  • If registration fails, show "This shortcut is in use by another app" and keep the previous one.

Acceptance criteria

  • Both shortcuts can be changed in Settings and work immediately, without a relaunch.
  • Choices persist across launches, and "Reset to default" restores ⌥⇧⌘R and ⌥⇧⌘P.
  • A shortcut that can't be registered shows an error and never leaves the app without a working shortcut.
  • The File menu, the menu bar menu, the setup window hint, the popover footer and the HUD tooltips all show the current shortcuts.
  • Unit tests cover the display string and the modifier conversions.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgood first issueGood for newcomersuxUser experience and interface polish

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions