Forum Discussion

almmatt's avatar
almmatt
Contributor
10 years ago

Get cursor coordinates over tested object?

Does anyone have a way a to get the cursor coordinates over a tested object during test execution?

 

I am working an unsupported control and I have a method to place the cursor over a particular region of this control. If I use TestComplete to send a double click, it will click at 0,0 of that object instead of where the cursor is currently residing. If I had a way to get the current coordinates of the mouse cursor I could send that to the double-click action.

 

Alternatively, if there was a way to send a double click command to the current cursor location, that would work too.

 

Any ideas?

  • almmatt's avatar
    almmatt
    10 years ago

    Thanks for the assistance everyone, I was able to get what I needed. Here's the script I wrote to get the current X & Y coordinates and double click the object at that point.

     

    var screenMouseX, screenMouseY, controlPoint, onscreenObj;
    
    function double_click()
    {
    
    //Gets current mouse cursor coordinates on screen
    screenMouseX = Sys.Desktop.MouseX;
    screenMouseY = Sys.Desktop.MouseY;
    
    Log.Message("X: " + screenMouseX + " Y: " + screenMouseY);
    
    //gets the object below the mouse cursor
    onscreenObj = Sys.ObjectFromPoint(screenMouseX,screenMouseY); 
    
    //converts the screen coordinates to coordinates relative to the object
    controlPoint = onscreenObj.ScreenToWindow(screenMouseX,screenMouseY);
    
    Log.Message("objX: " + controlPoint.X + " objY: " + controlPoint.Y);
    
    //double clicks the object from the converted coordinates
    onscreenObj.DblClick(controlPoint.X,controlPoint.Y);
    
    }
  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    In addition to Ryan's answer, you can convert screen coordinates to object-relative coordinates using:

     

    point = obj.ScreenToWindow(ScreenX, ScreenY) 
    • Colin_McCrae's avatar
      Colin_McCrae
      Community Hero

      By "cursor" .... do you mean the mouse pointer? In which case everything above should be all you need.

       

      Or do you mean a text cursor? In which case, need to look for something else .....

      • almmatt's avatar
        almmatt
        Contributor

        By cursor I was referring to the mouse pointer, yes.