views:

70

answers:

1

What is the equivalent of PostMessage/SendMessage in Windows on Mac OS X?

I have recently started out with Mac development, with most of my experience coming from Windows and nix.

I want to hook a window and simulate mouse clicks or keyboard presses. Also I want to be able to find a function like GetWindowText or any function that can get a certain text from a window.

A: 

One can send low-level events using Quartz event APIs such as CGEventPostToPSN. To get text from another app's window, I think your best bet would be the Accessibility APIs (just type "accessibility" in the Xcode search box), though I have no personal experience with that.

JWWalker
Can I simulate a button click on a certain object in a window with CGEventPostToPSN? It's a UIButton that I want to press.
John Williams
You asked about Mac OS X, but UIButton is from iOS. It looks like CGEventPostToPSN doesn't exist in iOS.
JWWalker
Oh, I thought it was called UIButton in OS X as well. Well OS X is my platform.
John Williams
OK, that would be NSButton. If you know its location, you could post a click event there.
JWWalker