Trying to recognize a right click on a NSStatusItem
I got a suggestion ( Thanks to Zoff Dino ) to use a NSClickGestureRecognizer
for that. But for some bizarre reason it isn't working as it should be. I am able to recognize a left click (buttonMask = 0x1
) but not a right-click (buttonMask = 0x2
). This is how I would like it to work but it isn't:
func applicationDidFinishLaunching(aNotification: NSNotification) {
// Insert code here to initialize your application
if let button = statusItem.button {
// Add right click functionality
let gesture = NSClickGestureRecognizer()
gesture.buttonMask = 0x2 // right mouse
gesture.target = self
gesture.action = "rightClickAction:"
button.addGestureRecognizer(gesture)
}}
func rightClickAction(sender: NSGestureRecognizer) {
if let button = sender.view as? NSButton {
NSLog("rightClick")
}
}
UPDATE:
I still did not manage to gets to work. Somehow it doesn't react on a right click (but changing the code on a left click) does. I guess some really simple issues are occurring that seem to block it from working. Even stranger is the fact that
gesture.buttonMask = 0x1
works on the left click.