Sign in to follow this  
Followers 0
Ousapik

Save Mouse coord and re-use it

2 posts in this topic

Hello,

I want to use mouse coord and click or drag at these coord when i want, but the mouse coord where i want to clic or drag change so i use a hotkey which store the position when it change.

I tried to make a script using MouseGetPos, MousClick and MouseClickDrag , draging or click at a fixed position i was successful but when i tried to hotkey a function to "save" the mouse position with MousegetPos, autoIt tell me "Variable used without being declared."

I tried these functions

Func Start()
    $StartPos = MouseGetPos()
EndFunc

Func Drag()
    $DragPos = MouseGetPos()
    MouseClickDrag("left", $DragPos[0], $DragPos[1], $StartPos[0], $StartPos[1], 0)
   
EndFunc

Func Click()
    
    MouseClick("left", [,$StartPos[0], $StartPos[1] [,1 [,0]]])

EndFunc

When i use the hotkey for Start i dont "save" the coords and i have an error.

Share this post


Link to post
Share on other sites



Your script should declare global variable so the variables referenced by a function won't be assumed local variables.

Global $StartPos

; ...
; ..

Func Start()
    $StartPos = MouseGetPos()
EndFunc

Func Drag()
    $DragPos = MouseGetPos()
    
    If IsArray($StartPos) Then _
        MouseClickDrag("left", $DragPos[0], $DragPos[1], $StartPos[0], $StartPos[1], 0)
   
EndFunc

Func Click()
    
    MouseClick("left", [,$StartPos[0], $StartPos[1] [,1 [,0]]])

EndFunc

..this way the $DragPos is local but it only get referenced by the function defining it.

Share this post


Link to post
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
Sign in to follow this  
Followers 0