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
2010-08-01 12:36:25
You've got an extra ` in there, confusing both the highlighter and potential copy-pasters ;)
You
2010-08-01 12:48:26
Fixed it, totally missed that, thanks.
Ashaman
2010-08-01 13:46:33
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
2010-08-01 17:44:40