Get mouse (cursor) position without event

By Xiaodong Liang

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(p
tUcs),                    &wcs,                     &dcs,                     0,                     result);          acutPrintf(              L"nModel Position (with UCS): [%f, %f, %f]n",             result[0], result[1], result[2]);

}


Comments

2 responses to “Get mouse (cursor) position without event”

  1. priya Avatar
    priya

    Hi can anybody help me to Get mouse (cursor) position without event using COM API.

  2. JamesOneil Avatar
    JamesOneil

    Bag essentials and all point of the order is firm for the advancement for the citizens. He joys of the B2B Tech Marketing Agency are implied for the field. The tip is argued for the top of the bag items or the true value for all positions for thk reform for the links for al buyers.

Leave a Reply to JamesOneilCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading