sindresorhus / KeyboardShortcuts

⌨️ Add user-customizable global keyboard shortcuts (hotkeys) to your macOS app in minutes
https://swiftpackageindex.com/sindresorhus/KeyboardShortcuts/documentation/keyboardshortcuts/keyboardshortcuts
MIT License
1.94k stars 181 forks source link

Request for minimal working example with Storyboard #173

Closed nguyenvukhang closed 3 months ago

nguyenvukhang commented 3 months ago

After trying all sorts of minimal working examples (and failing) just to get one RecorderCocoa to show up, can I humbly request for a simple "helloworld" level MWE with these settings?

Screenshot 2024-05-25 at 15 33 24

What I've tried so far is to

  1. Initialize the project as shown above
  2. Set the ViewController.swift file to
import Cocoa
import KeyboardShortcuts

extension KeyboardShortcuts.Name {
    static let toggleUnicornMode = Self("toggleUnicornMode")
}

class ViewController: NSViewController {
    @IBOutlet var button: NSView!
    let recorder = KeyboardShortcuts.RecorderCocoa(for: .toggleUnicornMode)

    override func viewDidLoad() {
        super.viewDidLoad()
        button.addSubview(recorder)
    }
}

But nothing shows up. Any help is appreciated. Thanks.

nguyenvukhang commented 3 months ago

Turns out, adding

recorder.frame = CGRect(x: 0, y: 0, width: 100, height: 25)

before button.addSubview(recorder) is one way to get it to work.