Mouse Cursor Control

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury, Rain

Post Reply
ocnuybear
Pro Scripter
Posts: 64
Joined: Sun Jul 15, 2018 5:14 pm

Mouse Cursor Control

Post by ocnuybear » Fri Aug 03, 2018 10:34 am

Say you want to see where the mouse cursor has moved to - you can use this script to move the mouse on a small area or make the mouse move in a box form with starting coordinates, Width & Height and speed.

Script can also be used for mouse move animation if needed moving in a small square.

This script will demonstrate the square movement on Windows Paint.

Code: Select all

RunProgram>%SYS_DIR%\mspaint.exe
//Starting coordinates
Let>X_start=200
Let>Y_start=200
//Width of box/square to be drawn
Let>Width=100
Let>Height=500
//Amount of pixels moved per loop - will affect speed of mouse
Let>Xd=1
Let>Yd=1
Let>X_new=X_start
Let>Y_new=Y_start

Let>X_new=X_start
Let>Y_new=Y_start

//These control X & Y direction and also which Axe Y or X must be moved next
Let>X_moved=0
Let>Y_moved=0
Let>Y_direction=1
Let>X_direction=1
Let>XY=1
Wait>0.2

Let>z=0
While>z<1000
  //Let>z=z+1

  IF>{(%X_moved% > %Width%) OR (%X_moved% = %Width%)}
    Let>XY=XY*-1
    Let>X_moved=0
    Let>X_direction=X_direction*-1
  ENDIF

  IF>{(%Y_moved% > %Height%) OR (%Y_moved% = %Height%)}
    Let>XY=XY*-1
    Let>Y_moved=0
    Let>Y_direction=Y_direction*-1
  ENDIF

  IF>XY=1
    Let>X_new={%X_new%+(%Xd%*%X_direction%)}
    Let>X_moved=X_moved+Xd
  ELSE
    Let>Y_new={%Y_new%+(%Yd%*%Y_direction%)}
    Let>Y_moved=Y_moved+Yd
  ENDIF
  
  //Added to demonstrate movement of mouse
  SetFocus>Paint*

  MouseMove>%X_new%,%Y_new%
  LClick
  
  //Will affect speed of mouse
  Wait>0.001
  //Stops mouse when square is done
  IF>{(%X_new%=%X_start%) AND (%Y_new%=%Y_start%)}
    EXIT>0
  ENDIF
Endwhile


Post Reply