git clone https://github.com/1c7/testHotKey.git
cd testHotKey
open .
Double click testHotKey.xcodeproj
Find a easy to use Shortcut library for my Swift macOS app project.
Seem like there are only 2 lib
I want to listen CTRL + 3
, Space
shortcut for my app.
Show HotKey
doesn't work
but Magnet
does
HotKey
Github issue
Figuring out why HotKey
doens't work and fix it.
I prefer use HotKey
over Magnet
, because HotKey
have better syntax (easier)
Here is comparison:
HotKey
snippet
let hotKey = HotKey(key: .r, modifiers: [.command, .option])
hotKey.keyDownHandler = {
print("Pressed at \(Date())")
}
Magnet
snippet
if let keyCombo = KeyCombo(keyCode: 11, carbonModifiers: 4352) {
let hotKey = HotKey(identifier: "CommandControlB", keyCombo: keyCombo, target: self, action: #selector())
hotKey.register() // or HotKeyCenter.shared.register(with: hotKey)
}
@objc func magnetKey(){
print("Magnet Work! \(Date())")
}
no idea what is keyCode: 11
and carbonModifiers: 4352
what if I only want listen Space
key? or Ctrl + 3
? How do I do it?
identifier: "CommandControlB"
seen like only for unregister
, not sure