NS の座標点 p を CG の座標点 q に変換するだけなら、プライマリスクリーンの高さから p.y を引いた値を q.y にすればよいです。
q.x = p.x q.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - p.y
所与の NSEvent に対応する CGEvent の位置を求めるなら、
NSEvent *ne; // given event CGEventRef e = [ne CGEvent]; CGPoint q = CGEventGetLocation(e);
マウスの現在位置の CG 座標を求めるだけなら、
CGEventRef e = CGEventCreate(NULL); CGPoint q = CGEventGetLocation(e); CFRelease(e);
等々。
E.g.,
#!/bin/bash TEMPDIR="$(mktemp -d ~/desktop/temp_XXXX)" && cd "$TEMPDIR" || exit cat <<'EOF' > main.m #import <Foundation/Foundation.h> #import <AppKit/AppKit.h> #import <ApplicationServices/ApplicationServices.h> int main (int argc, char **argv) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // screen coordinates NSPoint p = [NSEvent mouseLocation]; fprintf(stdout, "%-6s x=%.1f, y=%.1f\n", "NS", p.x, p.y); // convert screen coordinates to global display coordinates NSRect r = [[[NSScreen screens] objectAtIndex: 0] frame]; p.y = r.size.height - p.y; fprintf(stdout, "%-6s x=%.1f, y=%.1f\n", "CG/NS", p.x, p.y); // global display coordinates CGEventRef e = CGEventCreate(NULL); CGPoint q = CGEventGetLocation(e); CFRelease(e); fprintf(stdout, "%-6s x=%.1f, y=%.1f\n", "CG", q.x, q.y); [pool release]; return 0; } EOF CC=/usr/bin/gcc "$CC" \ -framework Foundation \ -framework AppKit \ -framework ApplicationServices \ -o ns-cg-coord \ main.m ./ns-cg-coord