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)
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)
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?
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.
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
Hi Dennis,
Doesn't Obj.Click(-1, -1, skCtrl) work for you ?
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
Subject | Author | Latest Post |
---|---|---|