soffes / HotKey

Simple global shortcuts in macOS
MIT License
902 stars 79 forks source link

Initializing hotkey in viewDidLoad() results in nothing when shortcut is activated #28

Open brendanballon opened 4 years ago

brendanballon commented 4 years ago

Here's my code (I'm just making a test application)

import Cocoa
import HotKey

class ViewController: NSViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let hotkey = HotKey(keyCombo: KeyCombo(key: .p, modifiers: [.control, .command]))
        hotkey.keyDownHandler = {
            print("Something should happen")
        }
        // Do any additional setup after loading the view.
    }

    override var representedObject: Any? {
        didSet {
        // Update the view, if already loaded.
        }
    }

    }

I'm just wondering if I'm doing any of this right, as you may be able to tell I'm a beginner.

tuanphamanh91 commented 1 month ago

@brendanballon hi, got same error, how did you handle it?