diff --git a/Sources/KeyboardShortcuts/CarbonKeyboardShortcuts.swift b/Sources/KeyboardShortcuts/CarbonKeyboardShortcuts.swift index a57c0ff..98bcd44 100644 --- a/Sources/KeyboardShortcuts/CarbonKeyboardShortcuts.swift +++ b/Sources/KeyboardShortcuts/CarbonKeyboardShortcuts.swift @@ -81,14 +81,20 @@ enum CarbonKeyboardShortcuts { return } - if KeyboardShortcuts.isMenuOpen { + if KeyboardShortcuts.isEnabled { + if KeyboardShortcuts.isMenuOpen { + softUnregisterAll() + RemoveEventTypesFromHandler(eventHandler, hotKeyEventTypes.count, hotKeyEventTypes) + AddEventTypesToHandler(eventHandler, rawKeyEventTypes.count, rawKeyEventTypes) + } else { + softRegisterAll() + RemoveEventTypesFromHandler(eventHandler, rawKeyEventTypes.count, rawKeyEventTypes) + AddEventTypesToHandler(eventHandler, hotKeyEventTypes.count, hotKeyEventTypes) + } + } else { softUnregisterAll() RemoveEventTypesFromHandler(eventHandler, hotKeyEventTypes.count, hotKeyEventTypes) - AddEventTypesToHandler(eventHandler, rawKeyEventTypes.count, rawKeyEventTypes) - } else { - softRegisterAll() RemoveEventTypesFromHandler(eventHandler, rawKeyEventTypes.count, rawKeyEventTypes) - AddEventTypesToHandler(eventHandler, hotKeyEventTypes.count, hotKeyEventTypes) } } diff --git a/Sources/KeyboardShortcuts/KeyboardShortcuts.swift b/Sources/KeyboardShortcuts/KeyboardShortcuts.swift index 7e243c7..9e498f8 100644 --- a/Sources/KeyboardShortcuts/KeyboardShortcuts.swift +++ b/Sources/KeyboardShortcuts/KeyboardShortcuts.swift @@ -37,6 +37,19 @@ public enum KeyboardShortcuts { */ static var isPaused = false + /** + Enable/disable monitoring of all keyboard shortcuts. + */ + public static var isEnabled = true { + didSet { + guard isEnabled != oldValue else { + return + } + + CarbonKeyboardShortcuts.updateEventHandler() + } + } + /** Set according to the opening state of your NSMenu if you want your keyboard shortcuts to work when it is open.