Hmm, again I think it nearly works. It compiles and runs but I don't seem to be able to use the returned theOrigin properly (when I try to Print theOrigin.X the app just crashes even in debug mode). I looked up NSPoint on developer.apple.com and it is simply a struct with x and y fields as FLOATS, nothing else.
Here's what I have so far:
This file is called cocoamouse.m
And here is my test code:
I tried this:
but it wouldn't compile, said "Unable to convert from 'Byte Ptr' to 'TAccuratePoint'"
Any ideas? Thx.
Here's what I have so far:
This file is called cocoamouse.m
#include <AppKit/AppKit.h> void ccNSGetCursorPos(int *x,int *y){ NSPoint mouseLoc = [NSEvent mouseLocation]; *x = mouseLoc.x; *y = mouseLoc.y; } int getActiveWindowOSX(){ NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init]; NSApplication *myApp; myApp=[NSApplication sharedApplication]; NSWindow *myWindow = [myApp keyWindow]; [pool release]; // return *NSWindow; } NSPoint ccGetWindowOrigin(){ NSApplication *myApp = [NSApplication sharedApplication]; NSWindow *myWindow = [myApp keyWindow]; NSRect myFrame = [myWindow frame]; NSPoint theOrigin = myFrame.origin; return theOrigin; };
And here is my test code:
SuperStrict Import "cocoa_mouse.m" Extern Function ccNSGetCursorPos(x:Int Ptr, y:Int Ptr) Function ccGetWindowOrigin: TAccuratePoint() End Extern Type TAccuratePoint Field X# Field Y# End Type Function GetScreenPointerPos(x:Int Var, y:Int Var) ccNSGetCursorPos(Varptr x, Varptr y) End Function Graphics 640,480, 0 While Not KeyDown(KEY_ESCAPE) Cls Local x:Int, y:Int GetScreenPointerPos(x, y) DrawText "Pos = " + x + ", " + y, 50, 50 Local p:TAccuratePoint = ccGetWindowOrigin() Print p.x Flip Wend End
I tried this:
Function ccGetWindowOrigin: Bye Ptr()
but it wouldn't compile, said "Unable to convert from 'Byte Ptr' to 'TAccuratePoint'"
Any ideas? Thx.