开发者

Getting cursor position on Mac OS X

开发者 https://www.devze.com 2023-03-10 22:55 出处:网络
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,开发者_Python百科 but I

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,开发者_Python百科 but I'd like to make my program cross-platform.


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.)

0

精彩评论

暂无评论...
验证码 换一张
取 消