(Programming) Generating mouse events

aelf

Registered
I am a complete newbie to programming for OSX, but have recently got hold of one and want to code a very simple script. I've looked around the net and am completely bamboozled (I've done the same thing for Windows and it was very straightforward).

Basically, I want to write a C program (or Python if possible) that opens a plain text data file, of the format:

x:100,y:200
x:50,y:150

It should read in the values and generate mouse events to move the mouse to those coordinates on the screen (regardless of what application is currently in focus). I'd like to be able to move the mouse to absolute coordinates, and also later relative coordinates.

I have no problem reading in the data file correctly, but I cannot figure out how to generate a mouse event!

I know it is possible since they do something similar in this application:
http://www.orderedbytes.com/controllermate/buildingblocks.html

My research found this:
http://developer.apple.com/documentation/AppleScript/Reference/StudioReference/sr3_app_suite/chapter_3_section_57.html#//apple_ref/doc/uid/20011217-BAJICIDD
but thats more about capturing events than creating them.

If there are any clues I'd be very grateful - a C or python library that I could use would be perfect, but any help would save my hairline!
Cheers in advance!
 
If you read the Carbon Event Programming Guide, in the Carbon Event Manager Tasks section is documentation on how to create your own events. Using the method described in the documentation requires you to write C code.

If you want to use Python, have a look at PyObjC. It lets you write Cocoa applications in Python. You'll want to read the Cocoa documentation on notifications and event handling if you go this route.
 
Back
Top