Find or Wait for Object then Click other object

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Sam71
Junior Coder
Posts: 23
Joined: Tue Mar 12, 2019 10:10 pm

Find or Wait for Object then Click other object

Post by Sam71 » Mon Jun 17, 2019 10:37 am

Hi Again!,

I have been playing around with Macro Scheduler again and trying out some new commands. What I want to do is creat a loop where it finds UIAutomation Name: Some text, then click an object thats further up left on the screen. Is this possible?.

User avatar
Sam71
Junior Coder
Posts: 23
Joined: Tue Mar 12, 2019 10:10 pm

Re: Find or Wait for Object then Click other object

Post by Sam71 » Tue Jun 18, 2019 4:13 am

Here is my attempt, its not working but hopefully it explains further what I'm trying to do.

Code: Select all

SetFocus>Web App - Mozilla Firefox
label>webapp
if
UIClick>{"Web App - Mozilla Firefox"},{"Search"}
endif

label>noresults
FindWindowWithText>No results found,0,strTitle
If>NumFound>0
UIClick>{"Web App - Mozilla Firefox"},{""}
goto>webapp

else

GetWindowHandle>Find Object Wizard,hWndParent
If>NumFound>0
FindObject>hWndParent,TTabPage,,1,hWnd,X1,Y1,X2,Y2,result
UIClick>{"Web App - Mozilla Firefox"},{"Buy Now"}
endif
endif

goto>noresults
This is how I used to do it:

Code: Select all

SetFocus>PS4 Remote Play
Label>Restart
FindImagePos>C:\Users\Documents\Tra.bmp,WINDOW:PS4 Remote Play,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  HoldKey>v,48,0 // Cross
  HoldKey>a,50,0 // D-Pad Left
  HoldKey>g,50,0 // Circle
  HoldKey>t,48,0 // Triangle
Endif

label>restarttwo
FindImagePos>C:\Users\Documents\NoResults.bmp,WINDOW:PS4 Remote Play,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  HoldKey>v,48,0 // Cross
  goto>Restart
else
Label>ResultStart
FindImagePos>C:\Users\Sam Wade\Documents\SearchResults0.bmp,WINDOW:PS4 Remote Play,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  goto>SearchResult
endif
endif
goto>restarttwo

User avatar
Sam71
Junior Coder
Posts: 23
Joined: Tue Mar 12, 2019 10:10 pm

Re: Find or Wait for Object then Click other object

Post by Sam71 » Tue Jun 18, 2019 8:03 am

Also is it possible to bind a keyboard key to an object?

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

Re: Find or Wait for Object then Click other object

Post by Marcus Tettmar » Tue Jun 18, 2019 12:10 pm

Can you explain what you mean?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

User avatar
Sam71
Junior Coder
Posts: 23
Joined: Tue Mar 12, 2019 10:10 pm

Re: Find or Wait for Object then Click other object

Post by Sam71 » Tue Jun 18, 2019 7:32 pm

Marcus Tettmar wrote:
Tue Jun 18, 2019 12:10 pm
Can you explain what you mean?
Hi Marcus,

What I mean is for example, In a webpage you have buttons like submit, preview, save draft etc. I'd like to assign a shortcut key to some of these, if I press say the "S" it will save draft, if I press "T" key it will submit. I hope that clarifies it better.

User avatar
PepsiHog
Automation Wizard
Posts: 517
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Re: Find or Wait for Object then Click other object

Post by PepsiHog » Mon Jun 24, 2019 5:53 pm

@Sam71,
If you use the Object wizard to identify the object (button) you'd like to click, the next tab in Object Wizard let's you choose what action to take. If everything goes well, you will be able to choose "Left click the object" Assuming that......

You then could use OnEvent to setup a "hotkey" that will cause the object(button) to be left clicked. You can use the forum to get a list of the VK codes. If for example, you wanted it to click the button when you press 'F2' the OnEvent wold look like this.....

OnEvent>Key_Down,VK113,0,TheSubroutine
(this is one off the top of my head that I know, use the code for the key you'd like to use.)

The Subroutine is where you have the code inserted for the "action to take" with the Object Wizard. So when you press 'F2" OnEvent calls the subroutine, and the code there will click the object(button).

Ofcourse, this all relies on the buttons being objects and that the object wizard is able to identify them.

Hope this helps,
PepsiHog
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

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