AutoCAD API provides AcEdInputPointManager.Inputpointmonitor which can monitor any input of the user, including mouse. API also allows you to monitor Windows message. Sometimes you may just need to get the current mouse position without any event. The following is code demo. Actually, it just get the current cursor position and convert it to AutoCAD coordinate. It also takes UCS into consideration.
static void getMousePosition(void)
{
//get cursor position by Windows API
POINT CursorPos;
GetCursorPos(&CursorPos);
acedGetAcadDwgView()->ScreenToClient(&CursorPos);
//Returns the viewport number based on
// Windows client coordinates.
int vpNum = acedGetWinNum(CursorPos.x, CursorPos.y);
//Converts coordinates from AutoCAD
// drawing window
//to current active viewport's coordinates
acedDwgPoint acPt, newPt;
acedCoordFromPixelToWorld(vpNum,
CursorPos,
acPt);
double worldPoint[3];
acedCoordFromPixelToWorld(vpNum,
CPoint(CursorPos.x,
CursorPos.y) ,
worldPoint);
acutPrintf(
L"\nModel Position (no UCS): [%f, %f, %f]\n",
worldPoint[0],
worldPoint[1],
worldPoint[2]);
//Take UCS translation in consideration
AcGeMatrix3d mat;
acedGetCurrentUCS(mat);
AcGePoint3d ptUcs(worldPoint[0],
worldPoint[1],
worldPoint[2]);
ptUcs.transformBy(mat.inverse());
resbuf wcs;
wcs.restype = RTSHORT;
wcs.resval.rint = 0;
resbuf dcs;
dcs.restype = RTSHORT;
dcs.resval.rint = 2;
//translate the WCS coordinate to UCS
double result[3];
acedTrans(asDblArray(ptUcs),
&wcs,
&dcs,
0,
result);
acutPrintf(
L"\nModel Position (with UCS): [%f, %f, %f]\n",
result[0], result[1], result[2]);
}