Script to move the mouse / click without seeing it happen?

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

User avatar
aboredprogrammer
Junior Coder
Posts: 40
Joined: Wed Jan 27, 2010 6:31 am

Post by aboredprogrammer » Sat Jan 30, 2010 10:09 am

Thanks for all of the help.. I'm sorry for being annoying, but I'm just trying to get back in to the swing of things here.. Therefore, may I ask a couple more simple questions that seem to baffle me somehow?

1. I was using image recognition for my program, until I noticed that It was non-stop clicking in the same spot for some reason. I decided to just go the route of getpixelcolor>... How do I get the Pixel color of an item if I do not know where it is? Getpixelcolor>then is it %x%,%y%,(pixel),(label)? is that how it works? So, if this pixel color exists, then go to Label>SB_F_BM

2. You guys helped me with moving the mouse "stealthy", this works, but I think it needs some help which I do not know how to aide. For example, lets say the mouse starts in the position of 100,100.. it moves to where it should, then back to 100,100 right away (this is exactly what I want). However, if I try to move the mouse while the script is running it ALWAYS shoots it back to the 100,100 spot like someone is fighting me with the mouse. I want the mouse to be completely free when this program is running, not shoot back to 100,100.. here is the script below..

Code: Select all

Label>SB_F_BM
  SetFocus>in Ali Baba Slots*
  GetCursorPos>CurX,CurY
  GetScreenRes>sX,xY
  ScreenCapture>0,0,sX,sY,d:\screen.bmp
  FindImagePos>C:\Windows\System32\nlhtml\bm.bmp,SCREEN,20,1,XPos,YPos,NumFound
  Wait>1
  if>imgs>0
  Mou>XPos_0,YPos_0
  Lcl
  Mou>CurX,CurY
  Endif
goto>SB_F_BM

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Sat Jan 30, 2010 5:41 pm

This macro that is running continuously takes over the mouse control once the image is found. You will not be able to use the mouse until the image is gone. If you put in a delay before continuing the loop, you will have that Wait> amount to move the mouse.

There is no delay so this will always be doing a left click and returning to 100,100 as long as the image is found. Once the image is gone, the mouse will not be moved by the macro, and the next tiime the image is found the latest mouse position will be used, vs. the initial 100,100.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Post by gdyvig » Sat Jan 30, 2010 6:20 pm

I'm not sure if this is the same thing Bob is saying, but here is what I think you want.

Instead of always returning to 100,100 first find the current mouse position left the the user using GetCursorPos and use that for your return location.

Gale

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Sat Jan 30, 2010 6:39 pm

Gale, that is what he is doing, using GetCusorPos, and moving back.
But his current complaint is that he cannot use the mouse.
However, if I try to move the mouse while the script is running it ALWAYS shoots it back to the 100,100 spot like someone is fighting me with the mouse.
He is right, the someone fignting him is his macro in a tight loop with no delays.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Sat Jan 30, 2010 7:08 pm

You can get the cursor position before moving the mouse, then move the mouse back to the stored position after the mouse move. Like so...

Code: Select all

GetCursorPos>Xpos,Ypos
MouseMove>500,500
MouseMove>Xpos,Ypos

User avatar
aboredprogrammer
Junior Coder
Posts: 40
Joined: Wed Jan 27, 2010 6:31 am

Post by aboredprogrammer » Sat Jan 30, 2010 7:30 pm

Hello,

I feel terrible having you guys all caught up in trying to help me with my project, but I would just like everyone here at the forums to know that I am very appreciative. Below is a better understanding of what I'm doing, what images I'm capturing, ECT.

Here is the "Bet Max" button that I have the image recognition look for, which it finds all the time: Image
And after clicking the Bet Max button, it looks like this: Image

For some reason, the image recognition will still be clicking the bet max button, even when it is already pushed, therefore, the mouse goes crazy.. How would I go about finding the pixel color of this, without knowing exactly where it is, since I do not want to move the screen to 0,0?

Once again, thank you for your patience with me.

aboredprogrammer[/img]

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Post by gdyvig » Sat Jan 30, 2010 10:56 pm

Hi aboredprogrammer.

I see you are capturing NumFound and checking for imgs in the posted code.

Try looking for both pushed and unpushed bm buttons.

Code: Select all

 FindImagePos>C:\Windows\System32\nlhtml\bma.bmp,SCREEN,20,1,XPosa,YPosa,imgsa
 FindImagePos>C:\Windows\System32\nlhtml\bmb.bmp,SCREEN,20,1,XPosb,YPosb,imgsb

  Wait>1
  if>imgsa>0
  Mou>XPosa_0,YPosa_0
  Lcl
  endif
  if>imgsb>0
  //button already pushed
  //user free to operate mouse
  wait>0.1
  endif



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

Post by JRL » Sun Jan 31, 2010 1:54 am

Or just reset the "imgs" variable. See comments.

Code: Select all

Label>SB_F_BM
  SetFocus>in Ali Baba Slots*
  GetCursorPos>CurX,CurY
  GetScreenRes>sX,xY
  ScreenCapture>0,0,sX,sY,d:\screen.bmp
  FindImagePos>C:\Windows\System32\nlhtml\bm.bmp,SCREEN,20,1,XPos,YPos,NumFound
  Wait>1

  \\Ok,  so the script found the "Bet Max" button on the screen.
  if>imgs>0


    //Since the "Bet Max" button was found, variable "imgs" was set to some number greater than zero.
    //After the "Bet Max" button is pressed, the "Bet Max" button visibly changes but the value of the variable 
    //(which is actually controlling the script) does not automatically change...
    //So you have to change the variable value in the script.
    //If you don't change the value,  every time the script loops around it runs the
    //mouse repositioning and button clicking as if it has just found the "Bet Max" button anew.


    Let>imgs=0


    Mou>XPos_0,YPos_0
    Lcl
    Mou>CurX,CurY
  Endif
goto>SB_F_BM

User avatar
aboredprogrammer
Junior Coder
Posts: 40
Joined: Wed Jan 27, 2010 6:31 am

Post by aboredprogrammer » Sun Jan 31, 2010 4:05 pm

gdyvig: Your code works perfectly, however, for some reason the mouse clicks the bet max button, and stays there. It will not return to the previous mouse position, making it almost look like the mouse isn't moving.


JRL: Your script last night when I tried it found the bet max button, but it didn't "Loop" , therefore it only clicked the button once. When I tried it this morning it keeps giving me the error: "Line 89: invalid mousemove command" Here is line 89: Mou>XPos_0,YPos_0

thanks,
aboredprogrammer

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Sun Jan 31, 2010 7:21 pm

Make sure you have removed any unwanted trailing spaces. They usually creep in when doing copy/paste with forum.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
aboredprogrammer
Junior Coder
Posts: 40
Joined: Wed Jan 27, 2010 6:31 am

Post by aboredprogrammer » Mon Feb 01, 2010 4:05 am

Hello,

It's working, thanks to everyone's help! I greatly appreciate it. Mouse moves stealthy, fast, and can detect the image! I will paste the part of the code I had to switch around.

Code: Select all

 GetCursorPos>CurX,CurY
  Wait>1
  if>imgsa>0
  Mou>XPosa_0,YPosa_0
  Lcl
  if>imgsb>0
  endif
  //button already pushed
  //user free to operate mouse
  Mou>CurX,CurY
  endif
for some reason, I had to move the getcursorpos> down under where the FindImagePos> is located, then I had to put the EndIf below, not above, the if>imgsb>0

:D Thank you all so much!

aboredprogrammer

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