Does not work

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Boxxxed
Junior Coder
Posts: 26
Joined: Fri Mar 19, 2010 7:20 pm

Does not work

Post by Boxxxed » Fri Mar 26, 2010 4:52 pm

Label>Waitt
ScreenCapture>589,531,719,688,%SCRIPT_DIR%\CEx.bmp
FindImagePos>%SCRIPT_DIR%\CExact.bmp,%SCRIPT_DIR%\CEx.bmp,40,0,Q,W,NumFoundxx
If>NumFoundxxQ_0,W_0
MouseMove>Q_0,W_0
LClick

This would work before, when the tab was already set correctly, when the tab is not set, this should set it, however it fails to click at all in the end.

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

Post by Marcus Tettmar » Mon Mar 29, 2010 6:49 am

Hi,

So, your code captures a portion of the screen, then looks for a smaller bitmap within it.

The code has been corrupted by the forum, so you might want to repost it using the CODE button so that the code format is preserved.

Anyway, if it "does not work" then I guess we can translate that to "FindImagePos did not find the image" which would therefore mean the image you are looking for is not in the portion of screen you captured, or at least, given the tolerance provided there is not a sufficient match.

You might find this helpful:
http://www.mjtnet.com/blog/2009/02/13/i ... -mistakes/
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

Boxxxed
Junior Coder
Posts: 26
Joined: Fri Mar 19, 2010 7:20 pm

Post by Boxxxed » Mon Mar 29, 2010 5:30 pm

waitscreenimage works and does find the image so I don't see why findimage pos for the same image at the same instance doesn't produce position variables. The loop is set to keep going until it does find an image, the problem is with the position, the mouse doesn't move at all.


Well I'm trying to edit this post to correct code but too bad the forum gimps it no matter what
Last edited by Boxxxed on Mon Mar 29, 2010 5:42 pm, edited 9 times in total.

Boxxxed
Junior Coder
Posts: 26
Joined: Fri Mar 19, 2010 7:20 pm

Post by Boxxxed » Mon Mar 29, 2010 5:32 pm

Forum still corrupts code anyway

If I try to correct the code in the forums it continues to change it to something else

I give up trying to post on this site, I will upload a text file.

http://www.speedyshare.com/files/21678759/COde.txt

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

Post by Marcus Tettmar » Mon Mar 29, 2010 6:55 pm

No, if you use the CODE button and disable html and smilies, the code will be fine.

Your code/message:

Code: Select all

Label>Waitt
FindImagePos>%SCRIPT_DIR%\CharacterExact.bmp,SCREEN,40,0,Q,W,NumFoundxx
If>NumFoundxx<1,Waitt
else
endif
wait>1
MouseMove>Q_0,W_0
LClick

This above code works



Label>Waitt
ScreenCapture>589,531,719,688,%SCRIPT_DIR%\CharacterEx.bmp
FindImagePos>%SCRIPT_DIR%\CharacterExact.bmp,%SCRIPT_DIR%\CharacterEx.bmp,40,0,Q,W,NumFoundxx
If>NumFoundxx<1,Waitt
else
endif
wait>1
MouseMove>Q_0,W_0
LClick

This above partially works.

It finds the picture because the loop ends and the script continues, however

it doesn't move the mouse to correct position. Something about the mouse position variables doesn't

happen right.
Ok, some comments. First, as you have a label in your If line you do not need the else and endif lines.

Second: In the second example you are looking within a bitmap file NOT the screen. The positions returned are therefore WITHIN the bitmap. They are NOT screen coordinates. If you want to translate them to screen coordinates then you would need to add the top left position of the original screen capture. You captured from 589,531, so you'd need to add these to Q_0,W_0 to turn them into the equivalent screen coordinates:

Let>x=Q_0+589
Let>y=W_0+531
MouseMove>x,y

I do hope you understand why your second example is not returning an absolute screen coordinate. It does not know that the bitmap you have given it is anything to do with the screen. All it can do is return the position of a match within the bitmap. The position returned is the position relative to the top left of the bitmap image.

So, make your code as follows:

Code: Select all

Label>Waitt
ScreenCapture>589,531,719,688,%SCRIPT_DIR%\CharacterEx.bmp
FindImagePos>%SCRIPT_DIR%\CharacterExact.bmp,%SCRIPT_DIR%\CharacterEx.bmp,40,0,Q,W,NumFoundxx
If>NumFoundxx<1,Waitt
wait>1
Let>x=589+Q_0
Let>y=531+W_0
MouseMove>x,y
LClick
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

Boxxxed
Junior Coder
Posts: 26
Joined: Fri Mar 19, 2010 7:20 pm

Post by Boxxxed » Mon Mar 29, 2010 8:11 pm

Ah I was wondering that before but no one mentioned it and I almost thought it was automatic, thanks I'll give this a shot.

Also, I used the code button but it would always change the code on me, I tried multiple times.

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

Post by Marcus Tettmar » Mon Mar 29, 2010 8:23 pm

Well, it can't be automatic because a) it does not know that the bitmap file you gave it was a screen shot, and b) no screen coordinates are passed to it. It is simply being asked to return the position within one bitmap of another. And that is exactly what it is doing.

Think of it like this. Say the needle was found right at the top left - it would return 0,0. But say the haystack was a screen grab taken from origin 500,500 on the screen. So the pixel at 0,0 returned by FindImagePos would match the pixel at 500,500 on the screen. No good moving to 0,0 on the screen as that has nothing to do with 0,0 of the scanned bitmap. Only if the bitmap was taken starting from position 0,0 on the screen would that work.

For all it cares the image you gave it is a scan of a photograph you took of your cat. It might be clever, but it is not clairvoyant.

Of course, when you specify SCREEN you're asking it to scan the entire screen, starting from 0,0. So a match at 0,0 would also be 0,0 of the screen, since there's a direct mapping.

When pasting code to the forum use the code button and also, for good measure, check "Disable HTML in this post" and "Disable smiilies in this post" and you'll be good to go.
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