Mike2012
Mike2012

Reputation: 7725

Looking for a cocoa method to simulate a button press that does not have an Event as a parameter

I need to simulate a button press on my Cocoa button programatically and I am trying to do this on cocotron which unfortunately does not have the NSEvent method: mouseEventWithType:location:modifierFlags:timestamp:windowNumber:context:eventNumber:clickCount:pressure: implemented. Is there anyway to programatically simulate a button press without having to create an event?

Upvotes: 1

Views: 1560

Answers (1)

Peter Hosey
Peter Hosey

Reputation: 96323

Don't forget to look in superclasses when you're looking for something. All NSControls, including all NSButtons, respond to a performClick: message.

That said, is it really appropriate for you to simulate a button press? If you just want something done, it's generally better to directly tell the controller to do it.

Upvotes: 6

Related Questions