私はステータスバーアプリケーション(Swift 3)を構築しており、ユーザーが左右をクリックしたかどうかによって異なるアクションを呼び出す必要があります。これまで私が持っていたことは次のとおりです。Swift:NSStatusItemの左クリックイベントと右クリックイベントを認識します
var statusItem = NSStatusBar.system().statusItem(withLength: -1)
statusItem.action = #selector(AppDelegate.doSomeAction(sender:))
let leftClick = NSEventMask.leftMouseDown
let rightClick = NSEventMask.rightMouseDown
statusItem.button?.sendAction(on: leftClick)
statusItem.button?.sendAction(on: rightClick)
func doSomeAction(sender: NSStatusItem) {
print("hello world")
}
私の機能が呼び出されず、その理由が見つかりませんでした。私は助けていただきありがとうございます!
これは実際には機能しますが、 '.rightMouseUp'のようにしか見えません。 '.rightMouseDown' – joe
' button.sendAction'行も変更しましたか? –
doh!ステートメントではなく、 'sendAction'で変更されました!うまく動作します、ありがとうx) – joe