Jump to content

Return Multiple Variables


Recommended Posts

Hi im new here as you can see this is my first post +D..

Im a nub in teh world of programin and right now im tryin to learn to program by myself.. i found autoIt nice & nubie friendly so i decided to use autoIt .. :lmao: anyways lets get to teh problem

for practice i made a func that will detect mouse movements(very simple func below in a quote)

i wanted the func to return mutiple variables(instead of just the 1 i wish the func also returns the new x and y) like MouseGetPos,EX: $var = MouseGetPos it returns x in $var[0] and y in $var[1]) , how would i do to make it return just like MouseGetPos? i tried returnin an array but doesnt seem to work(the return value turns out to be 0) & i have refer to the help file and done searches in the forum but no luck =( (mebe im just bad at searchin)...mm so mebe you guys can help me out by givin me so pointers..

Thanks in advance for any help! :P

Local $tempX

Local $tempY

func MouseMoved()

while 1

$mousePos = MouseGetPos()

$tempX = $mousePos[0]$tempY = $mousePos[1]

$newMousePos = MouseGetPos()

if($newMousePos[0] <> $tempX Or $newMousePos[1] <> $tempY) Then

return 1

Else

return 0

EndIf

Sleep(50)

Wend

EndFunc

Link to post
Share on other sites

maybe like this

Local $tempX = "N/A"
Local $tempY = "N/A"


HotKeySet("{F9}", "MouseMoved")
HotKeySet("{ESC}", "Terminate")

While 1
    sleep(20)
WEnd


func MouseMoved()

$newMousePos = MouseGetPos()
if($newMousePos[0] <> $tempX Or $newMousePos[1] <> $tempY) Then
    MsgBox(64, "Mouse Info", "Old mouse position  x: " & $tempX & "  y: " & $tempY & @CRLF & @CRLF & _
    "New mouse position  x: " & $newMousePos[0] & "  y: " & $newMousePos[1] & "   ")
    $tempX = $newMousePos[0]
    $tempY = $newMousePos[1]
EndIf
EndFunc

Func Terminate()
    Exit
EndFunc

8)

NEWHeader1.png

Link to post
Share on other sites

HotKeySet("{ESC}", "Terminate")

While 1
    Sleep(20)
    $a_MosPos = MouseMoved()
    If IsArray($a_MosPos) Then
        ToolTip("Mouse Info" & @CRLF & @CRLF & _
                "Mouse position  x: " & $a_MosPos[1] & "  y: " & $a_MosPos[2])
    EndIf
    
WEnd


Func MouseMoved()
    $newMousePos = MouseGetPos()
    Return StringSplit($newMousePos[0] & "|" & $newMousePos[1], "|"); creates array, array[0] = size
EndFunc  ;==>MouseMoved

Func Terminate()
    Exit
EndFunc  ;==>Terminate

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...