Add isEnabled

This commit is contained in:
decodism 2023-02-20 12:57:45 +01:00
parent ce5d0f1931
commit 935d9eb63d
2 changed files with 24 additions and 5 deletions

View File

@ -81,14 +81,20 @@ enum CarbonKeyboardShortcuts {
return 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() softUnregisterAll()
RemoveEventTypesFromHandler(eventHandler, hotKeyEventTypes.count, hotKeyEventTypes) RemoveEventTypesFromHandler(eventHandler, hotKeyEventTypes.count, hotKeyEventTypes)
AddEventTypesToHandler(eventHandler, rawKeyEventTypes.count, rawKeyEventTypes)
} else {
softRegisterAll()
RemoveEventTypesFromHandler(eventHandler, rawKeyEventTypes.count, rawKeyEventTypes) RemoveEventTypesFromHandler(eventHandler, rawKeyEventTypes.count, rawKeyEventTypes)
AddEventTypesToHandler(eventHandler, hotKeyEventTypes.count, hotKeyEventTypes)
} }
} }

View File

@ -37,6 +37,19 @@ public enum KeyboardShortcuts {
*/ */
static var isPaused = false 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. Set according to the opening state of your NSMenu if you want your keyboard shortcuts to work when it is open.