tags:

views:

44

answers:

1
+1  Q: 

Mouse coordinates

How can i get mouse coordinates in C under Mac?

+1  A: 

I'm not avare of any fully only C implementation, but in the foundation framework of OSX (10.5+) there is a function called "HIGetMousePosition". You should be able to integrate this with your C program.

http://allancraig.net/index.php?option=com_content&view=article&id=137:getting-mouse-coordinates&catid=39:objective-c&Itemid=86 shows this example implementation:

int main (int argc, const char * argv[])
{

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

HIPoint point;
HICoordinateSpace space = 2;
HIGetMousePosition(space, NULL, &point);

printf("%.2f %.2f", point.x, point.y);

[pool drain];
return 0;
}
Ashaman
You've got an extra ` in there, confusing both the highlighter and potential copy-pasters ;)
You
Fixed it, totally missed that, thanks.
Ashaman
You say it's in the foundation framework, but the declaration is in CarbonEventsCore.h, in HIToolbox.framework, a subframework of Carbon.framework. I don't think there's any need for an autorelease pool for this.
JWWalker