Mousemove+Animation>ImagePos Help

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Joelyboy0991
Junior Coder
Posts: 24
Joined: Thu Oct 11, 2018 1:19 pm

Mousemove+Animation>ImagePos Help

Post by Joelyboy0991 » Mon Dec 03, 2018 3:41 am

Hey all

i can write my own find image pos and they work fine with added random tinkering aswell,
but now im trying to do it with Mousemove to imagepos with animation from current Cursor X,Y Pos
but i cant get it to work,

i keep getting errors and others of the same type on different lines.
Screenshot (17).png
i believe im not writing in the % and parentheses [{( proper.
I hope somone can clear up what im doing wrong as it looks like it should work.

This is my Current Script:
-----------------------------------------------

Label>Start
Random>700,delay
Let>delay=delay/2000
//Message>delay

Send>f
Wait>0.487
Wait>delay
ScreenCapture>311,337,1433,749,%TEMP_DIR%\screenrect.bmp
FindImagePos>%BMP_DIR%\image_1.bmp,%TEMP_DIR%\screenrect.bmp,0.10,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
Wait>delay
Goto>Loop
Else
Wait>delay
Goto>Start
Endif

Label>Loop
Random>700,delay
Let>delay=delay/2000
//Message>delay

GetCursorPos>XCursor,YCursor,csType
FindImagePos>C:\Users\*****\Documents\Macro Scheduler 14\*********\**********.bmp,SCREEN,0,1,%XArr%,%YArr%,NumFound,CCOEFF


// While either XCursor is not in the correct location...

While>{(%XCursor%<>%XArr%) and (%YCursor%<>%YArr%)}
// If X axis distance between current and target is greater than 5 then move
// Negative move
If>{(%XCursor%-%XArr%)>5}
Let>XCursor=XCursor-5
else
// Positive move
If>{(%XCursor%-%XArr%)<-5}
Let>XCursor=XCursor+5
else
// Distance is less then 5, move cursor to desired position
Let>XCursor=XArr
endif
endif

// If Y axis distance between current and target is greater than 5 then move
// Negative move
If>{(%YCursor%-%YArr%)>5}
Let>YCursor=YArr-5
else
// Positive move
If>{(%YCursor%-%YArr%)<-5}
Let>YCursor=YArr+5
else
// Distance is less then 5, move cursor to desired position
Let>YCursor=YArr
endif
endif
MouseMove>XArr,YArr

EndWhile
Goto>Loop

Thank you for taking time to look into my question
Cheers!

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: Mousemove+Animation>ImagePos Help

Post by hagchr » Mon Dec 03, 2018 8:17 am

Hi, one thing that stands out is that your XArr and YArr resulting from FindImagePos> are really arrays and you also need to use an index, eg XArr_0 for the first match. So try %XArr_0% and %YArr_0% instead of %XArr% and %YArr%.

Joelyboy0991
Junior Coder
Posts: 24
Joined: Thu Oct 11, 2018 1:19 pm

Re: Mousemove+Animation>ImagePos Help

Post by Joelyboy0991 » Mon Dec 03, 2018 3:42 pm

Hi,

thank you for looking to my question,

do you mean i would need to add %XArr_0% %YArr_0% to the findimagepos result only or to all of the
%XArr% %Yarr%

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: Mousemove+Animation>ImagePos Help

Post by hagchr » Mon Dec 03, 2018 3:57 pm

XArr is the name of an array which contains (possible) multiple values. These values are then referred to by using XArr_0, XArr_1, XArr_2, ... etc. depending on what findimagepos> finds.

So in findimagepos> you use XArr and YArr. When you want to refer to the results in other places/comparisons you use XArr_0, XArr_1 ... Here I guess you just get one value, ie XArr_0 and YArr_0. As you already do, it is important to enclose with %% when used in formulas.

Joelyboy0991
Junior Coder
Posts: 24
Joined: Thu Oct 11, 2018 1:19 pm

Re: Mousemove+Animation>ImagePos Help

Post by Joelyboy0991 » Tue Dec 04, 2018 3:35 am

Hey all,

so i have made some progress, i now have no errors ... But!

i have captured a icon image from the desktop i,e Steam Icon ( it is placed in the middle at the top of the screen)

when i run the code, the mouse always seems to start at 647,898 and does a animation move to 1022,523(centre of screen roughly) but then it stops.


1: i don't understand why when on starting the script the mouse always jumps to 647,898
2: and why it only moves to 1022,523
3: shouldn't each time i run this script it should get the Current Mouse position and then do the mouse move from the point..

the script it still running, and if i move my mouse manually it does move up to the icon but in clunky movements and only if i move the mouse manually,

is someone able to test the code and change the Findimage Capture poses to a image on their desktop or choosing and run, so you can get a idea,

i cant see where i have gone wrong.

i dont see why its so hard for me to get a smooth accurate Mousemove to the image found,

using the standard wizard works every time but as soon as i have tried to make a mouse move from the current mousepos with this method im having troubles.
----------------------------------------------------------------------------------------------------------
Here is my code so far,
-----------------------------------------------------------------------------------------------------------

OnEvent>KEY_DOWN,VK46,0,ForceQuit
SRT>ForceQuit
Exit>0
END>ForceQuit

Label>preStart

Random>700,delay
Let>delay=delay/2000
//Message>delay


run>sndvol.exe
WaitWindowOpen>Volume Mixer - Speakers (High Definition Audio Device)
Wait>0.114
MoveWindow>Volume Mixer - Speakers (High Definition Audio Device),40,60
Wait>delay
Setfocus>Volume Mixer - Speakers (High Definition Audio Device)
Wait>0.102
Press LCtrl
Wait>Delay
Press F12
Wait>0.087
Release LCtrl
Wait>delay
Mousemove>647,898
Lclick
Wait>delay


Label>Startmain
Random>700,delay
Let>delay=delay/2000
//Message>delay

Send>f
Wait>0.487
Wait>delay

/GetCursorPos>XCursor,YCursor,csType

//Find
FindImagePos>%BMP_DIR%\image_3.bmp,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
/MouseMove>XArr_0,YArr_0
/Endif



Wait>delay
Goto>Loop
Else
Wait>delay
Goto>Startfish
Endif

Label>Loop
Random>700,delay
Let>delay=delay/2000
/Message>delay

FindImagePos>%BMP_DIR%\image_3.bmp,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF

GetCursorPos>XCursor,YCursor,csType

/Wait>delay

// While either XCursor is not in the correct location...

While>{(%XCursor%<>%XArr_0%) and (%YCursor%<>%YArr_0%)}

// If X axis distance between current and target is greater than 5 then move
// Negative move

If>{(%XCursor%-%XArr_0%)>5}
Let>XCursor=XCursor-5
else
// Positive move
If>{(%XCursor%-%XArr_0%)<-5}
Let>XCursor=XCursor+5
else

// Distance is less then 5, move cursor to desired position

Let>XCursor=XArr_0
endif
endif

// If Y axis distance between current and target is greater than 5 then move
// Negative move

If>{(%YCursor%-%YArr_0%)>5}
Let>YCursor=YCursor-5
else
// Positive move

If>{(%YCursor%-%YArr_0%)<-5}
Let>YCursor=YCursor+5
else

// Distance is less then 5, move cursor to desired position
Let>YCursor=YArr_0

endif
endif
MouseMove>XCursor,YCursor
/Until>(XCursor=XArr_0) And (YCursor=YArr_0)

EndWhile
Goto>Loop

--------------------------------------------------------------------------------------------------------
thank you for the previous help and if anyone could help me debug this would be awesome,

i hope in the future they will add Mousemoves with animation/tween/easing/randomness as a feature to the wizard.

as a example Python has PyAutoGui : https://pyautogui.readthedocs.io/en/latest/mouse.html

i have used this in the past and is simple and powerful with many features.

Im sure macrosched can do the same as i have seen with just making a Mouse move animtion but,

have yet to find or develop one that can do it with the findimagepos

Joelyboy0991
Junior Coder
Posts: 24
Joined: Thu Oct 11, 2018 1:19 pm

Re: Mousemove+Animation>ImagePos Help

Post by Joelyboy0991 » Tue Dec 04, 2018 4:56 pm

Hey all,

Please tag this as solved :)!!!

i worked it out,

with much tinkering AND a couple of headaches!

I can now get the current X,Ypos of the mouse and move it to the found image X,Ypos... with animation :D!

so far it has been the hardest thing i have had to program but has been a awesome learning experience.

the animation from X,Y Mouse pos to the X,Y Image pos is smooth and accurate but a little robotic,

in the future would like to learn how to advance program the in between mouse moves with random small intervals
instead of a perfect straight tween to the x,y position

if anyone wants any tips ill gladly explain the process, still similar to the above code but had to change a lot of
small things...and it still needs work but, it works for what i need it for so far.

Cheers all

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