你有没有尝试过:
button.sendAction(on: [.leftMouseUp, .rightMouseUp])
然后看到该
doSomeAction()功能中按下了哪个鼠标键?
所以看起来像…
let statusItem = NSStatusBar.system().statusItem(withLength: NSSquareStatusItemLength)func applicationDidFinishLaunching(_ aNotification: Notification) { if let button = statusItem.button { button.action = #selector(self.doSomeAction(sender:)) button.sendAction(on: [.leftMouseUp, .rightMouseUp]) }}func doSomeAction(sender: NSStatusItem) { let event = NSApp.currentEvent! if event.type == NSEventType.rightMouseUp { // Right button click } else { // Left button click }}https://github.com/craigfrancis/datetime/blob/master/xpre/DateTime/AppDelegate.swift



