Is there an if statement for the cursor changing?

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
byrne86
Newbie
Posts: 7
Joined: Fri Oct 15, 2010 7:56 pm

Is there an if statement for the cursor changing?

Post by byrne86 » Sun Oct 17, 2010 8:19 pm

I have a script, that moves my mouse around, and I want to check if the cursor changes and if it does hold down the left mouse button until the cursor changes back to what it was.

I have the following script:

Code: Select all

//Move mouse in a circle
MouseMove>875,263
Wait>2
MouseMove>922,293
Wait>2
MouseMove>952,314
Wait>2
MouseMove>918,303
Wait>2
MouseMove>881,351
Wait>2
MouseMove>845,318
Wait>2
MouseMove>800,307
Wait>2
MouseMove>836,279
Iv tried using the following after each MoveMouse line

WaitCursorChanged>2
LDown

but it doesnt seem to work, in the help it says that the value of WaitCursorChanged saves its variable value to WCC_RESULT

so I tried using

WaitCursorChanged>2
if>WCC_RESULT=true
LDown
Else
...carry on with script

this also did not work, what is the easiest way to move the cursor, check if it has changed, hold down the left mouse button then release it if the cursor changes again.

Thanks

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

Post by JRL » Mon Oct 18, 2010 5:06 pm

Try something like this. It uses the Windows GetCursor library funtion to test the cursor and compare it to the cursors previous state.

Code: Select all

LibFunc>user32,GetCursor,InitialCursor

//Move mouse in a circle
MouseMove>875,263
Wait>2
GoSub>TestCursor
MouseMove>922,293
Wait>2
GoSub>TestCursor
MouseMove>952,314
Wait>2
GoSub>TestCursor
MouseMove>918,303
Wait>2
GoSub>TestCursor
MouseMove>881,351
Wait>2
GoSub>TestCursor
MouseMove>845,318
Wait>2
GoSub>TestCursor
MouseMove>800,307
Wait>2
GoSub>TestCursor
MouseMove>836,279


SRT>TestCursor
  LibFunc>user32,GetCursor,CursorNow
  If>CursorNow<>InitialCursor
    MDL>Cursor has changed from %InitialCursor% to %CursorNow%
    Let>InitialCursor=CursorNow
  EndIf
END>TestCursor

BTW, as posted, the "Move mouse in a circle" positions are not very circular.

How about something like this:

The soubroutine allows parameters to be passed that specify the centerpoint of the circle, the degrees of arc to use, and either the number of points in the arc or the angle between points in the arc.

Code: Select all

LibFunc>user32,GetCursor,InitialCursor
Let>up_down=1

//Usage:
//GoSub>GoAround,radius,arc length(+ CW or - CCW),angle between points,Center X,Center Y,[number of points (circumvents angle between points)]
GoSub>GoAround,80,-345,15,300,300

GoSub>GoAround,110,360,45,300,300

GoSub>GoAround,110,35,45,300,300,7

SRT>GoAround
  Let>radius=GoAround_var_1
  Let>ArcLength={%GoAround_var_2%*(pi/180)}
  Let>FocusX=GoAround_var_4
  Let>FocusY=GoAround_var_5
  
  Assigned>GoAround_var_6,AsgRes
  If>AsgRes=FALSE
    Let>GoAround_var_6=0
  EndIf
  If>{(%AsgRes%="TRUE")and(%GoAround_var_6%>0)}
    Let>DeltaAngle={%GoAround_var_2%/(%GoAround_var_6%-1)}
    Let>GoAround_var_6=0
  Else
    Let>DeltaAngle=GoAround_var_3
    If>{(%ArcLength%<0)and(%DeltaAngle%>0)}
      Let>DeltaAngle={%DeltaAngle%*-1}
    EndIf
  EndIf


  Let>angle=0
  Label>GoAroundStart
    Let>NextAngle={%angle%*(pi/180)}
    Let>NewXOff={(cos(%NextAngle%))*%Radius%}
    Let>NewYOff={(sin(%NextAngle%))*%Radius%}
    Let>NewX={round(%FocusX%-%NewXOff%)}
    Let>NewY={round(%FocusY%-%NewYOff%)}
    MouseMove>%NewX%,%NewY%
    Add>angle,%DeltaAngle%
    GoSub>TestCursor
    Wait>0.5
    Let>Delta={(%ArcLength%-%Nextangle%)}
  If>ArcLength>0
    If>Delta>0.001
      Goto>GoAroundStart
    EndIf
  Else
    If>Delta<-0.001
      Goto>GoAroundStart
    EndIf
  EndIf
END>GoAround

SRT>TestCursor
  LibFunc>user32,GetCursor,CursorNow
  If>CursorNow<>InitialCursor
    MDL>Cursor has changed from %InitialCursor% to %CursorNow%
/*
    If>up_down=1
      LDown
      Let>up_down=0
    Else
      Lup
      Let>up_down=1
    EndIf
*/
    Let>InitialCursor=CursorNow
  EndIf
END>TestCursor


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