4

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!

stefOCDP
  • 803
  • 2
  • 12
  • 20

2 Answers2

9

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

myButton.sendActionOn(Int(NSEventMask.LeftMouseDownMask.rawValue))
Code Different
  • 90,614
  • 16
  • 144
  • 163
0

Swift 5:

myButton.sendAction(on: NSEvent.EventTypeMask.leftMouseDown)
daxmacrog
  • 8,913
  • 1
  • 15
  • 16