Forum Discussion

dpaulus's avatar
dpaulus
Occasional Contributor
5 years ago

How to do a Ctrl+Click in a Text Edit Object without using coordinates

Hi,

I'm looking for a way to avoid having to use actual coordinates to do a Ctrl+Click Action.  The Click method has this capability, by using a 3rd paramter 'skCntrl', but to use this, I have to provide coordinates. e.g. Obj.Click(X, Y, skCtrl)

 

I found a similar post that dynamically figures out the coordinates of the Mouse (see below), which works great, but I would like it to look at the actual cursor position, instead of the mouse pointer position.  I can also get this to work if I only have 1 line of text, but the goal is to be able to search for any text (possibly in a long script in the Editor object),  set the cursor, and then do a Ctrl+Click, at that given point. 

 

Any Ideas?

 

Sample code to get coordinates dynamically by Mouse cursor position:

def Test():
  import time
  time.sleep(5)
  
  MyObject = Sys.Process("xxx").VCLObject("SyntaxEditorForm").VCLObject("mmoTop")

  # Gets current mouse cursor coordinates on screen
  screenMouseX = Sys.Desktop.MouseX
  screenMouseY = Sys.Desktop.MouseY
  Log.Message("X: " + str(screenMouseX) + " Y: " + str(screenMouseY))

  # Gets the object behind the mouse cursor
  onscreenObj = Sys.ObjectFromPoint(screenMouseX,screenMouseY)

  # Converts the screen coordinates to coordinates relative to the object
  controlPoint = MyObject.ScreenToWindow(screenMouseX,screenMouseY)
  Log.Message("objX: " + str(controlPoint.X) + " objY: " + str(controlPoint.Y))

  # Control Clicks object from the converted coordinates
  onscreenObj.Click(controlPoint.X,controlPoint.Y, skCtrl)

 

6 Replies

  • Vallalarasu_P's avatar
    Vallalarasu_P
    Frequent Contributor

    Read the object's height and width on runtime. 

    Find the center and click.

    Even if the object location changes,It will dynamically adjust.

    MyObject = Sys.Process("xxx").VCLObject("SyntaxEditorForm").VCLObject("mmoTop")
    MyObject_Height = MyObject.Height
    MyObject_Width = MyObject.Width

    Myobject.Click(MyObject_Height/2,MyObject_Width/2,skCtrl)

     

     

     

    • dpaulus's avatar
      dpaulus
      Occasional Contributor

      Hi Vallalarasu,

      Thank you for the reply.  This will give me the coordinates of the object itself, which I can get easily enough.  I need to get the coordinates of text within the control tho.  My question is how can I get the coordinates of the text (or cursor) itself, so I can do a Ctrl+Click within the object?

       

      For example, in the pic below, I have searched for '5' and placed the cursor there.  I now need to get the coordinates of that '5' character in the editor, so I can then use Click(x,y,skCtrl).  If there's a better way to do this, I'd much rather use that, but the only option I've found to do a Ctrl+Click is to use 'Click', with that 3rd parameter.

       

      Any other suggestions?

       

      • Vallalarasu_P's avatar
        Vallalarasu_P
        Frequent Contributor

        If the coordinates which you have to find is not an object and a text, Then it can be done by OCR.

         

          var textBlock = recognizedText.BlockByText(textToGet);
                if (textBlock != null)
                {
                  // Get info on bounds of the recognized text portion
                  var x = textBlock.Bounds.Left;
                  var y = textBlock.Bounds.Top;
                  var width = textBlock.Bounds.Width;
                  var height = textBlock.Bounds.Height;

        }

         

        Hope this matches the requirement.