Help: Possibility to use FindImagePos in region of SCREEN?

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
donkey111
Newbie
Posts: 4
Joined: Mon Apr 25, 2016 2:11 pm

Help: Possibility to use FindImagePos in region of SCREEN?

Post by donkey111 » Mon Apr 25, 2016 2:18 pm

Hello everyone,

First off I'd like to thank all active members on this forum. I'm new to scripting and by using this forum I was able to tackle a lot of problems.

I'd like to ask if it is possible to search for a certain image within a fixed region of an active window? That way I'll counter some occasional false positives and speed up the total script without using tight loops.

Thanks in advance!

Rick

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

Re: Help: Possibility to use FindImagePos in region of SCREE

Post by Marcus Tettmar » Mon Apr 25, 2016 2:23 pm

Yes, absolutely. FindImagePos can take SCREEN, or a Window title or a bitmap. That bitmap could be the result of a ScreenCapture of a portion of the screen. So e.g.:

ScreenCapture>x1,y,1,x2,y2,haystack.bmp
FindImagePos>needle,haystack.bmp .....

Just remember to add the origin of the screen capture (x1,y1) to the result of the FindImagePos to translate back to a screen position.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

donkey111
Newbie
Posts: 4
Joined: Mon Apr 25, 2016 2:11 pm

Re: Help: Possibility to use FindImagePos in region of SCREE

Post by donkey111 » Mon Apr 25, 2016 2:31 pm

Thanks for the quick reply. Sorry in case my question below isn't clear, English is not my native language.

I haven't used the screencapture functionality yet. The following question pops up in mind:
1) The background of my active window is dynamic and changes all the time, so I assume it has to make a new screencapture every time I'd like to use FindImagePos. Are these screencaptures being saved to my project folder or will the script overwrite the old screencapture when i takes a new one?

(edit: Sorry, I might have the solution already)
Thanks Marcus

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

Re: Help: Possibility to use FindImagePos in region of SCREE

Post by Marcus Tettmar » Mon Apr 25, 2016 3:02 pm

Yes you'd need to use ScreenCapture every time - do it immediately prior to your FindImagePos. You specify the path in the ScreenCapture command so it can be wherever you want!
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

donkey111
Newbie
Posts: 4
Joined: Mon Apr 25, 2016 2:11 pm

Re: Help: Possibility to use FindImagePos in region of SCREE

Post by donkey111 » Mon Apr 25, 2016 5:25 pm

Hi Marcus,

The following part is working:

Code: Select all

Screencapture>1582,303,1559,586,%TEMP_DIR%\screenrect.bmp
FindImagePos>here my path to needle file,%TEMP_DIR%\screenrect.bmp,10,1,XArr,YArr,NumFound, CCOEFF
If>NumFound>0
    MessageModal>Working
Else
MessageModal>Not Working
EndIf
Exit
However, I get a syntax error when i want to use the following MouseMove command in the "Working" (line 32) part:

Code: Select all

MouseMove>{%XArr_0%+1582},{%YArr_0%+303}
The error message: Line 32 Invalid Numeric Value for MouseMove command.

Do you see any problems in my code?

User avatar
JRL
Automation Wizard
Posts: 3531
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Help: Possibility to use FindImagePos in region of SCREE

Post by JRL » Mon Apr 25, 2016 9:21 pm

ScreenCapture> requires the first X,Y coordinates to be the upper left corner of the rectangle being captured and the second X,Y pair to be the lower right corner of the rectangle being captured. In your code the second X coordinate is smaller than the first x coordinate so there is no rectangle being captured. This will result in a failure for FindImagePos> which will mean there is no value for the variables "XArr_0" and "YArr_0". That all means the MouseMove> will fail with the message " Line 32 Invalid Numeric Value for MouseMove command"

Otherwise your code looks workable. If it were me I'd make sure the MouseMove was inside an If> block that tested for NumFound>0. You have that in the posted code but apparently the MouseMove is not in that If/EndIf block.

donkey111
Newbie
Posts: 4
Joined: Mon Apr 25, 2016 2:11 pm

Re: Help: Possibility to use FindImagePos in region of SCREE

Post by donkey111 » Mon Apr 25, 2016 10:59 pm

Otherwise your code looks workable. If it were me I'd make sure the MouseMove was inside an If> block that tested for NumFound>0. You have that in the posted code but apparently the MouseMove is not in that If/EndIf block.
You can't believe how stupid I feel after reading your reply. It solved my problem. Working troughout the night isn't a good thing to do I guess. The MouseMove command is inside the If statement (I try to follow the form of codes on this forum as much as possible. Many thanks!

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