Problem With FindImagePos/MouseMove

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
PaulSR
Pro Scripter
Posts: 65
Joined: Mon Aug 05, 2013 2:58 pm
Location: Edinburgh/Peterborough

Problem With FindImagePos/MouseMove

Post by PaulSR » Thu May 22, 2014 8:01 am

Hi,

I've started a new macro today which requires some image recognition in order to move the mouse around the screen and click on various areas. Every time I try this I'm getting an "invalid numeric value for mousemove command." error regardless of what image I use or where it's positioned.

What I've noticed is that in the watch list it's only generating an XARR=0 and there's no YARR at all. There's also an "l=<array>" and a "0.7=<array>" although I can't expand either so I'm guessing there's no content?

I've not had this problem before so I was wondering if it's related to the build? I'm running PRO 14.0.18

Thanks in advance,

Paul.

PaulSR
Pro Scripter
Posts: 65
Joined: Mon Aug 05, 2013 2:58 pm
Location: Edinburgh/Peterborough

Re: Problem With FindImagePos/MouseMove

Post by PaulSR » Thu May 22, 2014 8:24 am

Hmm I've just done a bit more with this - I was specifically trying to use image recognition on a website (https://secure.sign-up.to/) - it doesn't work there but it works on other websites fine along with full screen searches.

Is it possible that they've done something which can block it from working? For example I tried to perform mousemove on the yellow ".TO" on the page and it gives me that error.....

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

Re: Problem With FindImagePos/MouseMove

Post by Marcus Tettmar » Thu May 22, 2014 8:39 am

If the image is not found then the array of positions returned by FindImagePos would be empty - non existant. So if your next line is to move the mouse and you are assuming you have a position you're going to get an error.

E.g. consider this code:

Code: Select all

FindImagePos>needle,SCREEN,0.6,1,xArr,yArr,NumFound,CCOEFF
MouseMove>xArr_0,yArr_0
If FindImagePos does NOT find a match then your MouseMove is going to give the "invalid numeric value" error because xArr_0 and yArr_0 are not numeric - they are not variables - they contain nothing - no position was found!

Your code should be written:

Code: Select all

FindImagePos>needle,SCREEN,0.6,1,xArr,yArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>xArr_0,yArr_0
Endif
Better yet, something like:

Code: Select all

FindImagePos>needle,SCREEN,0.6,1,xArr,yArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>xArr_0,yArr_0
Else
  MessageModal>Sorry, the needle was not found
  Exit>0
Endif
So the issue is not the web page somehow mysteriously able to block FindIMagePos. The issue is simply that your needle image is not being found but you have nothing in your code to handle that eventuality.

If you were to use the debugger you'd see this - you'd see the num found result variable equal to zero and you'd instantly see no xArr_0, yArr_0 values. The debugger has the answers.

First fix your code so that you don't attempt to move to an invalid mouse position if the image is not found. Next you're probably going to want to work out why the image wasn't found. Perhaps you need to recapture it - perhaps they changed the appearance - perhaps it is dynamic - perhaps you're looking for it too early, or too late ..... and so on and so on. But the real issue here is simply that the image wasn't found but you still tried to move the mouse ....
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

PaulSR
Pro Scripter
Posts: 65
Joined: Mon Aug 05, 2013 2:58 pm
Location: Edinburgh/Peterborough

Re: Problem With FindImagePos/MouseMove

Post by PaulSR » Thu May 22, 2014 9:05 am

Hi Marcus,

The If>NumFound>0 is included - the watchlist doesn't display a returned value for NumFound but the code still progresses to the mousemove (stepping through with F8).

Code: Select all

FindImagePos>%BMP_DIR%\image_5.bmp,WINDOW:Sign-Up.to Login - Social, Mobile & Email Marketing,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
Endif
I tried it using a "search the whole screen" rather than specifying a window and that worked - so it seems to be very specifically to do with that window and looking at the window name it has a comma in there - that's going to make the macro think the window name stops after "Social" and screw up the rest of the FindImagePos line yes?

PaulSR
Pro Scripter
Posts: 65
Joined: Mon Aug 05, 2013 2:58 pm
Location: Edinburgh/Peterborough

Re: Problem With FindImagePos/MouseMove

Post by PaulSR » Thu May 22, 2014 9:08 am

and voila - changing the FindImagePos line to use a wildcard has solved it.

Code: Select all

//Find and Left Click Center of 
FindImagePos>%BMP_DIR%\image_6.bmp,WINDOW:Sign-Up.to Login - Social*,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
Endif

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

Re: Problem With FindImagePos/MouseMove

Post by Marcus Tettmar » Thu May 22, 2014 9:10 am

The problem is the comma in the window title of your FIndImagePos line. Change it to:

Code: Select all

FindImagePos>%BMP_DIR%\image_5.bmp,{"WINDOW:Sign-Up.to Login - Social, Mobile & Email Marketing"},0.7,1,XArr,YArr,NumFound,CCOEFF
Or:

Code: Select all

Let>win_title=Sign-Up.to Login - Social, Mobile & Email Marketing
FindImagePos>%BMP_DIR%\image_5.bmp,WINDOW:%win_title%,0.7,1,XArr,YArr,NumFound,CCOEFF
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

PaulSR
Pro Scripter
Posts: 65
Joined: Mon Aug 05, 2013 2:58 pm
Location: Edinburgh/Peterborough

Re: Problem With FindImagePos/MouseMove

Post by PaulSR » Thu May 22, 2014 12:52 pm

Thanks Marcus - I spotted it and just stuck a wildcard before the comma and removed the rest of the window descriptor and that worked - could've sworn I had hit post on a reply to that effect.

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

Re: Problem With FindImagePos/MouseMove

Post by Marcus Tettmar » Thu May 22, 2014 12:53 pm

You did. Looks like we replied almost at the same time :-)
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

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