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.

1 Answers1

0

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
  • 22,385
  • 6
  • 55
  • 76
  • 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 Aug 21 '10 at 11:01
  • You asked about Mac OS X, but UIButton is from iOS. It looks like CGEventPostToPSN doesn't exist in iOS. – JWWalker Aug 21 '10 at 16:17
  • Oh, I thought it was called UIButton in OS X as well. Well OS X is my platform. – John Williams Aug 21 '10 at 21:31
  • OK, that would be NSButton. If you know its location, you could post a click event there. – JWWalker Aug 21 '10 at 21:44
  • I still have no idea how to get a certain memory-segment of text from the external window. Accessibility has gotten me nowhere. I bump this in hope of getting a reply that may push me in the right direction. Also worth mentioning, I tried UIBrowser (http://pfiddlesoft.com/uibrowser/) but I could not find the specific text I was looking for with help from UIBrowser. – John Williams Nov 10 '10 at 09:47
  • Is the specific text you're looking for part of a standard control or field? If it's just drawn on the window using low-level graphics APIs, then it wouldn't be accessible unless the app takes special steps to make it so. – JWWalker Nov 10 '10 at 17:20