I am using event monitor to detect the key press event in swift. However, event monitor doesn't seem to detect command key or any other modifier key (shift, tab, opt ...) press. Is there a different way to detect modifier key press?. Note that I am not looking for a way to detect key combinations (ex: cmd+r) which can be done by using event.modifierFlags
, but a way to know when command key alone is pressed.
override func viewDidLoad() {
super.viewDidLoad()
NSEvent.addLocalMonitorForEvents(matching: .keyDown, handler: commandKey(evt:))
}
func commandKey(evt: NSEvent) -> NSEvent{
if evt.keyCode == 55 { //key code for command is 55
print("commanded")
}
return evt
}