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.
In Mouse Properties, on the Pointer Options tab, at the bottom, select Show location of pointer when I press the CTRL key, and then select OK. To see it in action, press CTRL.
In the ColorSync Utility app on your Mac, click Calculator in the toolbar of the ColorSync Utility window. Click the magnifying glass , then move the pointer over an area on the screen that you want to examine. The color values of pixels are shown in the ColorSync Utility window as you move the pointer.
The closest stock solution I personally use is to take activate the utility to take a screenshot of a screen portion ( Command ⌘ + Shift ⇧ + 4 ). The cursor will turn into a crosshair with the screen's horizontal and vertical pixel coordinates.
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 #define
s.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With