Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* gcc mouse.c -framework CoreFoundation -framework ApplicationServices */
- #define IS_MACOSX
- #include <CoreFoundation/CoreFoundation.h>
- #include <ApplicationServices/ApplicationServices.h>
- typedef struct {
- float x;
- float y;
- } MMPoint;
- MMPoint MMPointFromCGPoint(CGPoint point) {
- MMPoint dummy = { point.x, point.y };
- return dummy;
- }
- MMPoint getMousePos()
- {
- #if defined(IS_MACOSX)
- CGEventRef event = CGEventCreate(NULL);
- CGPoint point = CGEventGetLocation(event);
- CFRelease(event);
- return MMPointFromCGPoint(point);
- #elif defined(USE_X11)
- int x, y; /* This is all we care about. Seriously. */
- Window garb1, garb2; /* Why you can't specify NULL as a parameter */
- int garb_x, garb_y; /* is beyond me. */
- unsigned int more_garbage;
- Display *display = XGetMainDisplay();
- XQueryPointer(display, XDefaultRootWindow(display), &garb1, &garb2,
- &x, &y, &garb_x, &garb_y, &more_garbage);
- return MMPointMake(x, y);
- #elif defined(IS_WINDOWS)
- POINT point;
- GetCursorPos(&point);
- return MMPointFromPOINT(point);
- #endif
- }
- int main() {
- MMPoint pt = getMousePos();
- printf("%f %f\n", pt.x, pt.y);
- }
Advertisement
Add Comment
Please, Sign In to add comment