I am working on a macOS application and I would like to handle the local hotkey event (command + up arrow) in NSViewController .
Here's how I do it with Swift:
override func keyDown(with event: NSEvent) { let modifierkeys = event.modifierFlags.intersection(.deviceIndependentFlagsMask); let hasCommand = modifierkeys == .command; switch Int(event.keyCode) { case kVK_UpArrow where hasCommand: print("command up"); break; case kVK_ANSI_B where hasCommand: print("command B"); break; default: break; } }
When I create and press the + up command in the view, the console shows nothing. But when I press the + B command, the โBโ command is issued.
So why does this not work for Command + up? How do I achieve this?
source share