Get X,Y pos where a specifix text appears

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Niroj@Work
Pro Scripter
Posts: 63
Joined: Thu Dec 10, 2009 8:13 am

Get X,Y pos where a specifix text appears

Post by Niroj@Work » Thu Dec 17, 2009 6:40 am

Hi All,

Can I get the relative X,Y position on a window where a specific Text is found?
Also, can I catch the text linewise on a window screen?

What Exactly I am doing:
----------------------------
1)Finding a specific TEXT1 on the screen
2)If the TEXT1 is FOUND
>Start reading TEXT line by line TILL another specific TEXT2 found below the TEXT1
>IF TEXT2 NOT found Press Down

If not possible with direct command can you please provide any indirect method to do this?..
Thanks.. :)

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Dec 17, 2009 9:10 am

The only way to do this right now would be to loop through all pixels on the window, and get the text at that point. If you have a match you know the position. It would probably be quite slow though. E.g.:

Code: Select all

Let>TextToFind=great
GetWindowPos>Untitled - Notepad,xS,yS
GetWindowSize>Untitled - Notepad,w,h
SetFocus>Untitled - Notepad
Let>xE=xS+w
Let>yE=yS+h
Let>x=xS
Repeat>x
  Let>x=x+10
  Let>y=yS
  Repeat>y
    Let>y=y+10
    MouseMove>x,y
    GetTextAtPoint>x,y,text,cp
    Position>TextToFind,text,1,pText
    If>pText>0
      //found it:
      MessageModal>%TextToFind% found at %x%,%y%
      Exit>0
    Endif
  Until>y=yE
Until>x=xE
In the above I jump 10x10 pixels each time to speed it up. Unlikely to miss text with that amount.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Niroj@Work
Pro Scripter
Posts: 63
Joined: Thu Dec 10, 2009 8:13 am

Post by Niroj@Work » Thu Dec 17, 2009 10:49 am

Thanks Mtettmar,

But most of time it is hanging...
I am trying in different way by copying the window using "GetWindowTextEx" and spliting it for newlines and search it by using regular pattern matching...
My main motive was to reach the matched text by using arrow keys. That's why I need to get the position of matched string on the screen...

But this code will help me in many ways. I will make use of it.
Thanks a lot..
:)

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts