Marc
Marc

Reputation: 169

Getting cursor position on Mac OS X

I want to get the cursor position. Is there any standard function for this?

I'm trying to make my program in C++. I'd like to avoid Cocoa. Not that I have anything against it, but I'd like to make my program cross-platform.

Upvotes: 8

Views: 6220

Answers (1)

John Calsbeek
John Calsbeek

Reputation: 36497

You can use the following Core Graphics API, in CGEvent.h:

CGEventRef event = CGEventCreate(NULL);
CGPoint cursor = CGEventGetLocation(event);
CFRelease(event);

(Note that you can still use Cocoa in a cross-platform program, you just need to separate platform-specific code into different files instead of using #defines.)

Upvotes: 15

Related Questions