cancel
Showing results for 
Search instead for 
Did you mean: 

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

Highlighted
Occasional Contributor

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 6
Highlighted
Frequent Contributor

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

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)

 

 

 

With Regards
Vallalarasu Pandiyan | LinkedIn |Vallalarasu.p@gmail.com
Highlighted
Occasional Contributor

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

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?

 

pic1.jpg

Highlighted
Frequent Contributor

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

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. 

With Regards
Vallalarasu Pandiyan | LinkedIn |Vallalarasu.p@gmail.com
Highlighted
Occasional Contributor

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

Thanks for the reply Vallalarasu.  Yeah, I was hoping to stay away from using OCR, if possible.  There's numerous issues I have with using OCR.  I actually gave this a try and it didn't identify my text correctly.  I may have to just stick to using coordinates in this case, for now, unfortunately.  It seems like a relatively simple thing to just move the mouse to the actual cursor position and do a ctrl+click, but I guess not.  Anyway, I appreciate the help.

 

Dennis

Highlighted
Community Hero

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

Hi Dennis,

 

Doesn't Obj.Click(-1, -1, skCtrl) work for you ?

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
Highlighted
Occasional Contributor

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

Hi Alex,

Unfortunately not.  -1 is the default, so what that does is clicks in the middle of the recognized object - in this case, it's an editor object.  I need it to click on the actual text, which could be anywhere in the editor object itself.

 

Thanks,

Dennis

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors