stefOCDP
stefOCDP

Reputation: 863

How to trigger button action on leftMouseDown in Swift, Mac OSX, Cocoa

I want to trigger a button on left mouse down in my mac osx app using swift.

This is the way to do it in Objective-C

[myButton sendActionOn:NSLeftMouseDownMask];

I can't figure out how to do it in Swift. Can anybody help me out with my problem?

Thanks!

Upvotes: 4

Views: 1568

Answers (2)

daxmacrog
daxmacrog

Reputation: 9641

Swift 5:

myButton.sendAction(on: NSEvent.EventTypeMask.leftMouseDown)

Upvotes: 0

Code Different
Code Different

Reputation: 93181

After a bit of fiddling in Xcode, this is what worked for me (Swift 2.0):

myButton.sendActionOn(Int(NSEventMask.LeftMouseDownMask.rawValue))

Upvotes: 9

Related Questions