import Carbon /// System-wide ⌘Space via Carbon's RegisterEventHotKey (no Accessibility permission needed). /// Only fires once Spotlight's own ⌘Space shortcut is turned off. enum HotKey { private static var hotKeyRef: EventHotKeyRef? private static var handlerRef: EventHandlerRef? static var action: (() -> Void)? @discardableResult static func registerCommandSpace() -> Bool { var spec = EventTypeSpec(eventClass: OSType(kEventClassKeyboard), eventKind: UInt32(kEventHotKeyPressed)) InstallEventHandler(GetApplicationEventTarget(), { _, _, _ in HotKey.action?() return noErr }, 1, &spec, nil, &handlerRef) let id = EventHotKeyID(signature: 0x464C_4E43 /* FLNC */, id: 1) let status = RegisterEventHotKey(UInt32(kVK_Space), UInt32(cmdKey), id, GetApplicationEventTarget(), 0, &hotKeyRef) return status == noErr } }