Moving Mouse to Bitmap On Screen

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
stev3n
Junior Coder
Posts: 22
Joined: Thu Nov 01, 2007 1:13 am

Moving Mouse to Bitmap On Screen

Post by stev3n » Thu Nov 01, 2007 3:37 am

I think I may be mentally handicapped but,

how do I find a bitmap image on the screen, and move the mouse to that position? I don't think FindImagePos is what I want, but I could be wrong, because I'm not exactly sure how to use that function.

stev3n
Junior Coder
Posts: 22
Joined: Thu Nov 01, 2007 1:13 am

Post by stev3n » Thu Nov 01, 2007 4:00 am

Okay, I just had to take the whole screen to get it working. Now I'm trying to get it loop until there are no more possibilities, and this is what I have, but I think I have messed up something. Can anyone fix my loop? The problem seems to be that it doesn't move to new occasions of the bitmap, but it keeps moving to the original one and double clicks there. So I guess my question would be how to make it move to a new instance?

GetScreenRes>sX,sY
ScreenCapture>0,0,sX,sY,C:\blocks\maingame.bmp
FindImagePos>C:\blocks\ott.bmp,C:\blocks\maingame.bmp,0,0,X,Y,NumFound
If>NumFound>0
Repeat>NumFound
MouseMove>X_0,Y_0
LDblClick
Wait>0.5
Let>NumFound=NumFound-1
Until>NumFound=0
Endif

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

Post by Marcus Tettmar » Thu Nov 01, 2007 9:47 am

This is all you need:

Code: Select all

FindImagePos>C:\blocks\ott.bmp,SCREEN,0,1,X,Y,NumFound
If>NumFound>0
  Let>k=0
  Repeat>k
    Let>k=k+1
    MouseMove>X_%k%,Y_%k%
    LDblClick
    Wait>0.5
  Until>k=NumFound
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?

stev3n
Junior Coder
Posts: 22
Joined: Thu Nov 01, 2007 1:13 am

Post by stev3n » Thu Nov 01, 2007 2:57 pm

Thanks, that just about did it. I did get an error from MS, but I resolved it and I have the general loop.

I am doing this for a block game, and any two vertical or horizontal blocks, you double click, and they go away, making the board different, so I had to recode a little bit.

I now made it so it looks after each click for the blocks again (this is only for one color as of right now, and verticle). It works great, but once there aren't any blocks to click, it moves the mouse to the last position there was and clicks infinitely.

What am I doing wrong?


FindImagePos>C:\blocks\ott.bmp,SCREEN,0,1,X,Y,NumFound
If>NumFound>0
Let>k=NumFound
Repeat>k
Let>k=k-1
MouseMove>X_0,Y_0
LDblClick
Wait>1.5
FindImagePos>C:\blocks\ott.bmp,SCREEN,0,1,X,Y,NumFound
Until>k=NumFound
Endif

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

Post by Marcus Tettmar » Thu Nov 01, 2007 3:03 pm

You have Until>k=NumFound. But let's imagine k is on 5 and NumFound is now 0. K will now never equal 0. So perhaps this will do:

Until>{%k% >= %NumFound%}

So now it will stop if k is LARGER or EQUAL to NumFound. I think that's what 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?

stev3n
Junior Coder
Posts: 22
Joined: Thu Nov 01, 2007 1:13 am

Post by stev3n » Thu Nov 01, 2007 3:08 pm

That seems to only click once, and then the script ends

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

Post by Marcus Tettmar » Thu Nov 01, 2007 3:11 pm

In that case the second FindImagePos is finding less images than were previously found and k is currently set to a higher number. Which I thought was what you wanted.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

stev3n
Junior Coder
Posts: 22
Joined: Thu Nov 01, 2007 1:13 am

Post by stev3n » Thu Nov 01, 2007 3:17 pm

Well here's what I'm trying to achieve:

Find ott.bmp
Click there
Look again for ott.bmp
Click there
Until there are no ott.bmp
then stop clicking and eventually move to the next function

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

Post by Marcus Tettmar » Thu Nov 01, 2007 3:21 pm

Simplest approach:

Code: Select all

Label>SeekOTT
FindImagePos>C:\blocks\ott.bmp,SCREEN,0,1,X,Y,NumFound
If>NumFound>0
  MouseMove>X_0,Y_0
  LDblClick
  Goto>SeekOTT
Endif
So, if one is found, click on it, then start again. If none are found, move on.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

stev3n
Junior Coder
Posts: 22
Joined: Thu Nov 01, 2007 1:13 am

Post by stev3n » Thu Nov 01, 2007 5:14 pm

Alright, I got it going pretty decently I believe.
Is there any way to simplify this?

Label>LevelOne

FindImagePos>C:\blocks\ott.bmp,SCREEN,0,1,X,Y,NumFound
If>NumFound>0
GoTo>SeekOTT

FindImagePos>C:\blocks\oww.bmp,SCREEN,0,1,X,Y,NumFound
If>NumFound>0
GoTo>SeekOWW

FindImagePos>C:\blocks\bt.bmp,SCREEN,0,1,X,Y,NumFound
If>NumFound>0
GoTo>SeekBT

FindImagePos>C:\blocks\bw.bmp,SCREEN,0,1,X,Y,NumFound
If>NumFound>0
GoTo>SeekBW

FindImagePos>C:\blocks\special1.bmp,SCREEN,0,1,X,Y,NumFound
If>NumFound>0
GoTo>SeekSPECIAL1



Label>SeekOTT
FindImagePos>C:\blocks\ott.bmp,SCREEN,0,1,X,Y,NumFound
If>NumFound>0
MouseMove>X_0,Y_0
LDblClick
Goto>SeekOTT
If>Numfound=0
Wait>.05
GoTo>LevelOne
Endif
Endif

Label>SeekOWW
FindImagePos>C:\blocks\oww.bmp,SCREEN,0,1,X,Y,NumFound
If>NumFound>0
MouseMove>X_0,Y_0
LDblClick
Goto>SeekOWW
If>Numfound=0
Wait>.05
GoTo>LevelOne
Endif
Endif

Label>SeekBT
FindImagePos>C:\blocks\bt.bmp,SCREEN,0,1,X,Y,NumFound
If>NumFound>0
MouseMove>X_0,Y_0
LDblClick
Goto>SeekBT
If>Numfound=0
Wait>.05
GoTo>LevelOne
Endif
Endif

Label>SeekBW
FindImagePos>C:\blocks\bw.bmp,SCREEN,0,1,X,Y,NumFound
If>NumFound>0
MouseMove>X_0,Y_0
LDblClick
Goto>SeekBW
If>Numfound=0
Wait>.05
GoTo>LevelOne
Endif
Endif

Label>SeekSPECIAL1
FindImagePos>C:\blocks\special1.bmp,SCREEN,0,1,X,Y,NumFound
If>NumFound>0
MouseMove>X_0,Y_0
LDblClick
Goto>SeekSPECIAL1
If>Numfound=0
Wait>.05
GoTo>LevelOne
Endif
Endif

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

Post by Marcus Tettmar » Thu Nov 01, 2007 5:33 pm

You are doing the initial FindImagePos twice which will slow it down. You don't need to goto the top each time and you can simplify the If statements. This should be all you need:

Code: Select all

Label>SeekOTT
FindImagePos>C:\blocks\ott.bmp,SCREEN,0,1,X,Y,NumFound
If>NumFound>0
  MouseMove>X_0,Y_0
  LDblClick
  Goto>SeekOTT
Endif

Label>SeekOWW
FindImagePos>C:\blocks\oww.bmp,SCREEN,0,1,X,Y,NumFound
If>NumFound>0
  MouseMove>X_0,Y_0
  LDblClick
  Goto>SeekOWW
Endif

Label>SeekBT
FindImagePos>C:\blocks\bt.bmp,SCREEN,0,1,X,Y,NumFound
If>NumFound>0
  MouseMove>X_0,Y_0
  LDblClick
  Goto>SeekBT
Endif

Label>SeekBW
FindImagePos>C:\blocks\bw.bmp,SCREEN,0,1,X,Y,NumFound
If>NumFound>0
  MouseMove>X_0,Y_0
  LDblClick
  Goto>SeekBW
Endif

Label>SeekSPECIAL1
FindImagePos>C:\blocks\special1.bmp,SCREEN,0,1,X,Y,NumFound
If>NumFound>0
  MouseMove>X_0,Y_0
  LDblClick
  Goto>SeekSPECIAL1
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?

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