tags:

views:

215

answers:

1

I'm looking for or trying to write a testing suite in Python which will control the mouse/keyboard and watch the screen for changes.

The obvious parts I need are (1) screen watcher, (2) keyboard/mouse control.

The latter is explained here, but what is the best way to go about doing the former on OSX?

+1  A: 

I can't think of a smart way to "watch the screen for changes" in any OS nor with any language. On MacOSX, you can take screenshots programmatically at any time, e.g. with code like the one Apple shows at this sample (translating the Objective C into Python + PyObjC if you want), or more simply by executing the external command screencapture -x -T 0 /tmp/zap.png (e.g. via subprocess) and examining the resulting PNG image -- but locating the differences between two successive screenshot is anything but trivial, and the whole approach is time consuming (there's no way that I know to receive notification of generic screen changes, so you need to keep repeating this periodically -- eek!-).

Depending on what exactly you're trying to accomplish, maybe you can get away with something simpler than completely unconstrained "watching screen changes"...?

Alex Martelli