Find text on screen, then, else...

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
mduffin
Newbie
Posts: 19
Joined: Fri Nov 12, 2010 4:16 pm

Find text on screen, then, else...

Post by mduffin » Fri Nov 12, 2010 4:24 pm

I'd like to know if there is a way to have a script find text in the active window (it's a medical records program), and if it exists, then goto label, and if not, go to a different label..

I know some of the basics, but can't figure out the find text part..

When i run the example script for Text Capture it can see the text when i point to it..

In the past I've used the image tools (FindImagePos) to do something similar, but there doesn't seem to be a text recognition that works like the image tools.

Thanks for any help!

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

Post by Marcus Tettmar » Fri Nov 12, 2010 4:51 pm

You can do something like:

GetWindowTextEx>window_title,text
Pos>text_to_find,text,1,p
If>p>0
//text was found in window
Else
//text not found in window
Endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

mduffin
Newbie
Posts: 19
Joined: Fri Nov 12, 2010 4:16 pm

Post by mduffin » Fri Nov 12, 2010 5:49 pm

Thanks!
So I have this... but it just goes through to exit like it's not seeing the word..
I don't have a title for the window because it changes all the time, I hope that doesn't make it not look at the screen.
If the word Tanni is on screen I want it to run the script...

Label>Start

GetWindowTextEx>,text
Pos>Tanni,text,1,p
If>p>0
//text was found in window
Goto>Change


Else
//text not found in window
Goto>Exit

Endif


Label>Change
// Select and change old for new
Press F7
Wait>1
Press LShift
Press Down * 16
Wait>1
Release LShift
Wait>1
Press LCTRL
Wait>0.5
Send>v
Wait>0.2
Release LCTRL
Wait>2
Press Esc
Wait>1
Press Down
Wait>1
Press Enter

Goto>Start



Label>Exit
// Get out and go to the next one
Wait>1
Press Esc
Wait>1
Press Down
Wait>1
Press Enter

Goto>Start

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

Post by Marcus Tettmar » Fri Nov 12, 2010 7:54 pm

GetWindowText requires a window title.

Instead of GetWindowText you can use GetTextInRect and specify a rectangular portion of the screen which could be the entire screen - or the active window - in which case you don't care what the title is you just use whatever is on the screen.

So the following gets the text from the active window:

Code: Select all

GetActiveWindow>wTitle,x,y,w,h
GetTextInRect>x,y,{%x%+%w%},{%y%+%h%},text

Pos>Tanni,text,1,p
If>p>0
 //Tanni found 
Else
 //Not found
Endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

nodochau
Pro Scripter
Posts: 131
Joined: Wed Jan 16, 2019 12:59 pm

Re: Find text on screen, then, else...

Post by nodochau » Thu Jan 17, 2019 1:52 pm

Does it have to be exact Lower and Uppercase?
If yes then how to make the script to find text doesn't matter lower or uppercase...

User avatar
Grovkillen
Automation Wizard
Posts: 1009
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Find text on screen, then, else...

Post by Grovkillen » Thu Jan 17, 2019 3:03 pm

Usually you use the UpperCase>or LowerCase> commands to make them either uppercase or lowercase...
Let>ME=%Script%

Running: 15.0.24
version history

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