Add Kapture: menu-bar screenshot OCR app with Cmd+Shift+S hotkey
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import Carbon
|
||||
import AppKit
|
||||
|
||||
final class HotkeyManager {
|
||||
static let shared = HotkeyManager()
|
||||
|
||||
var onTrigger: (() -> Void)?
|
||||
|
||||
private var hotKeyRef: EventHotKeyRef?
|
||||
private var eventHandlerRef: EventHandlerRef?
|
||||
private var hotKeyID = EventHotKeyID(signature: 0x4B505452, id: 1)
|
||||
|
||||
private init() {}
|
||||
|
||||
func register() {
|
||||
var eventType = EventTypeSpec(
|
||||
eventClass: OSType(kEventClassKeyboard),
|
||||
eventKind: UInt32(kEventHotKeyPressed)
|
||||
)
|
||||
InstallEventHandler(GetApplicationEventTarget(), { _, _, _ in
|
||||
HotkeyManager.shared.onTrigger?()
|
||||
return noErr
|
||||
}, 1, &eventType, nil, &eventHandlerRef)
|
||||
|
||||
RegisterEventHotKey(
|
||||
UInt32(kVK_ANSI_S),
|
||||
UInt32(cmdKey | shiftKey),
|
||||
hotKeyID,
|
||||
GetApplicationEventTarget(),
|
||||
0,
|
||||
&hotKeyRef
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user