Jump to content

how can i set mouse location without moving it


Recommended Posts

hello i  am new to autoit forums and i need some help 

i want to set mouse location without moving it or use mousegetpos

my example is easy i need to declare 3 locations  and get them from other script

i have $X1 and $Y1 but what i need is  $location1 = $X1, $Y1 but i know won´t work like that

 

 

 

location.au3

Link to comment
Share on other sites

One option, you could employ an multidimensional array to hold the coordinate(s) then reference them as such.

;Enums just for ease of use
Global Enum $COORD_X, $COORD_Y

;Declare and Initilize Array
;                         X   Y
Local $aLocation[1][2]=[[780,600]]

MouseMove ($aLocation[0][$COORD_X], $aLocation[0][$COORD_Y])
ToolTip("mouse is here")

or

Global Enum $COORD_X, $COORD_Y
;Declare array and assign values "later"
Local $aLocation[1][2]
$aLocation[0][$COORD_X] = 780
$aLocation[0][$COORD_Y] = 600

MouseMove ($aLocation[0][$COORD_X], $aLocation[0][$COORD_Y])
ToolTip("mouse is here")

 

Not sure how much value that adds for you, but there's an example.

Link to comment
Share on other sites

Correct, you have to provide both coords to the mousemove function.  You could make a custom function that parses and passes the coords to the mousemove func.

crude example:
 

#include <StringConstants.au3>

_MoveMouse("780,600")

Func _MoveMouse($sCoords = "0,0")
    $aCoords = StringSplit($sCoords,",",$STR_NOCOUNT)
    If UBound($aCoords) <> 2 Then Return SetError(1,0,0)
    Return MouseMove($aCoords[0],$aCoords[1])
EndFunc

 

Link to comment
Share on other sites

i was just thinking anout fuction and then call the function, i am learning ...

thanks for the help

Quote

Func location1()

$X1 =780
$Y1 = 600


MouseMove ($X1, $Y1)
ToolTip("mouse is here")
Sleep(2000)

EndFunc

Func location2()

$X2 =600
$Y2 = 708


MouseMove ($X2, $Y2)
ToolTip("mouse is here")
Sleep(2000)

EndFunc

location1()

Location2()

 

Link to comment
Share on other sites

I got it solved. I made 3 funcitions and then call them from main file.

I need to call them like 20 times that´s why i wated more simple not always typing coords.

Func location1()

$X1 =780
$Y1 = 100


MouseMove ($X1, $Y1)
Sleep(100)
MouseClick("left",$X1,$Y1,1)


EndFunc

Func location2()

$X2 =780
$Y2 = 225


MouseMove ($X2, $Y2)
Sleep(100)
MouseClick("left",$X2,$Y2,1)

EndFunc

Func location3()

$X3 =780
$Y3 = 350

MouseMove ($X3, $Y3)
Sleep(100)
MouseClick("left",$X3,$Y3,1)

EndFunc

Once again thanks and sorry for spamming,  I am new.

Link to comment
Share on other sites

All good; if you want to improve your coding skillz, take another look at my example.  I created a custom (modular) function that I can provide coordinates to.  It's more efficient than copying and pasting more-or-less the same code over and over.  Write once, run many.

;untested
_MoveAndClickMouse(780,600)
_MoveAndClickMouse(780,225)
_MoveAndClickMouse(780,350)

Func _MoveAndClickMouse($X, $Y)
    MouseMove($X,$Y)
    Sleep(100)
    MouseClick("Left",$X,$Y,1)
EndFunc

Just a suggestion for consideration

Edited by spudw2k
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...