Jump to content

Help Needed... Array Frustration...


exfelon
 Share

Recommended Posts

I've been using autoit for a little while to do small tasks... I have a script that gets a predefined number of mouse clicks then repeats them one after another every 5 secs. Super easy to do, but if I need to change it, I have to edit the script to say add or subtract a certain number of clicks...

Global $Paused 
HotKeySet("{PAUSE}", "TogglePause") 
;HotKeySet("{ESC}", "Terminate") 
Opt("MouseClickDragDelay", 100) 

#include <Misc.au3>

Sleep(5000) 

SplashTextOn ( "Setup", "Leftclick Where You Need To", 400, 100, -1, -1, 1, "Ariel", 14 ) 
   While 1 
      Sleep ( 100 ) 
      If _IsPressed ( "01" ) Then 
         $pos = MouseGetPos() 
      ExitLoop 
      EndIf 
   WEnd 

   SplashOff() 
   $var1 = $pos[0] 
   $var2 = $pos[1] 
   Sleep (1000) 
   
SplashTextOn ( "Setup", "Leftclick on the Skill", 400, 100, -1, -1, 1, "Ariel", 14 ) 
   While 1 
      Sleep ( 100 ) 
      If _IsPressed ( "01" ) Then 
         $pos = MouseGetPos() 
      ExitLoop 
      EndIf 
   WEnd 

   SplashOff() 
   $var3 = $pos[0] 
   $var4 = $pos[1] 
   Sleep (1000) 
   
SplashTextOn ( "Setup", "Leftclick on the Skill", 400, 100, -1, -1, 1, "Ariel", 14 ) 
   While 1 
      Sleep ( 100 ) 
      If _IsPressed ( "01" ) Then 
         $pos = MouseGetPos() 
      ExitLoop 
      EndIf 
   WEnd 

   SplashOff() 
   $var5 = $pos[0] 
   $var6 = $pos[1] 
   Sleep (1000) 
   
SplashTextOn ( "Setup", "Leftclick on the Skill", 400, 100, -1, -1, 1, "Ariel", 14 ) 
   While 1 
      Sleep ( 100 ) 
      If _IsPressed ( "01" ) Then 
         $pos = MouseGetPos() 
      ExitLoop 
      EndIf 
   WEnd 

   SplashOff() 
   $var7 = $pos[0] 
   $var8 = $pos[1] 
   Sleep (1000) 
   
SplashTextOn ( "Setup", "Leftclick on the Skill", 400, 100, -1, -1, 1, "Ariel", 14 ) 
   While 1 
      Sleep ( 100 ) 
      If _IsPressed ( "01" ) Then 
         $pos = MouseGetPos() 
      ExitLoop 
      EndIf 
   WEnd 

   SplashOff() 
   $var9 = $pos[0] 
   $var10 = $pos[1] 
   Sleep (1000) 
   
SplashTextOn ( "Setup", "Leftclick on the Skill", 400, 100, -1, -1, 1, "Ariel", 14 ) 
   While 1 
      Sleep ( 100 ) 
      If _IsPressed ( "01" ) Then 
         $pos = MouseGetPos() 
      ExitLoop 
      EndIf 
   WEnd 

   SplashOff() 
   $var11 = $pos[0] 
   $var12 = $pos[1] 
   Sleep (1000) 
   
SplashTextOn ( "Setup", "Leftclick on the Skill", 400, 100, -1, -1, 1, "Ariel", 14 ) 
   While 1 
      Sleep ( 100 ) 
      If _IsPressed ( "01" ) Then 
         $pos = MouseGetPos() 
      ExitLoop 
      EndIf 
   WEnd 

   SplashOff() 
   $var13 = $pos[0] 
   $var14 = $pos[1] 
   Sleep (1000) 
   
SplashTextOn ( "Setup", "Leftclick on the Skill", 400, 100, -1, -1, 1, "Ariel", 14 ) 
   While 1 
      Sleep ( 100 ) 
      If _IsPressed ( "01" ) Then 
         $pos = MouseGetPos() 
      ExitLoop 
      EndIf 
   WEnd 

   SplashOff() 
   $var15 = $pos[0] 
   $var16 = $pos[1] 
   Sleep (1000) 
   
While 1 
    Sleep(5000)
    MouseClick ("left", $var1, $var2, 1) 
    Sleep(5000)
    MouseClick ("left", $var3, $var4, 1) 
    Sleep(5000)
    MouseClick ("left", $var5, $var6, 1)
    Sleep(5000)
    MouseClick ("left", $var7, $var8, 1) 
    Sleep(5000)
    MouseClick ("left", $var9, $var10, 1) 
    Sleep(5000)
    MouseClick ("left", $var11, $var12, 1) 
    Sleep(5000)
    MouseClick ("left", $var13, $var14, 1)
    Sleep(5000)
    MouseClick ("left", $var15, $var16, 1)
WEnd 

;Pause Script 
Func TogglePause() 
$Paused = NOT $Paused 
While $Paused 
sleep(100) 
ToolTip('Script Paused',0,0) 
WEnd 
ToolTip("") 
EndFunc 

Func Terminate() 
   Exit 0 
EndFunc

Today I decided I wanted to do it the right way.. I was going to build a small app that would ask the user how many iterations? then get that number of mouse clicks, then repeat them (possibly asking if for the time between clicks (1-5 secs or something)...

I figured an array would be the best way to do this. $aList[2][$iterations] something like that (2 columns of data, by how many rows the user defines)...

Global $Paused 
HotKeySet("{PAUSE}", "TogglePause") 
;HotKeySet("{ESC}", "Terminate") 
Opt("MouseClickDragDelay", 100) 

#include <Misc.au3>
#include <Array.au3>

Sleep(5000) 

;Get Input from user, ie: How Many Iterations?
$iterations = InputBox("Input Needed", "How Many Iterations?", "Enter a number 1-100", "", -1, -1, 0, 0)

Local $aList[2][$iterations]

For $i = 1 to $iterations


SplashTextOn ( "Setup", "Leftclick Where You Need To", 400, 100, -1, -1, 1, "Ariel", 14 ) 
   While 1 
      Sleep ( 500 ) 
      If _IsPressed ( "01" ) Then 
         $pos = MouseGetPos() 
      ExitLoop 
      EndIf 
   WEnd 

   SplashOff() 
   $aList[0][0] = $pos[0] 
   $aList[0][1] = $pos[1] [b];HOW DO I ADVANCE THESE VARIABLES FOR THE NEXT MOUSE CLICK?[/b]
   Sleep (1000) 
   
 Next 

   
While 1 
    Sleep(5000)
    MouseClick ("left", [b]$aList[0][0][/b], [b]$aList[0][1][/b], 1) [b];HOW DO I CALL fROM THE ARRAY HERE TO GET THE POSITIONS?[/b]

WEnd 

;Pause Script 
Func TogglePause() 
$Paused = NOT $Paused 
While $Paused 
sleep(100) 
ToolTip('Script Paused',0,0) 
WEnd 
ToolTip("") 
EndFunc 

;Get Mouse Clicks
;Func GetClick
;   not completed
;EndFunc


;Click Where Told To!
;Func Click
;       not completed
;EndFunc

;KILL THIS PROGRAM
Func Terminate() 
   Exit 0 
EndFunc

I'm lost... I know the end example isn't complete, but hopefully you see where I'm going with this. I don't know how to advance the variables when getting the 2nd-100th mouse clicks. But I don't know how to call the data from the array effeciently... So that one loop will advance through all X number mouse clicks. ugh I feel stupid not getting it.

Edited by exfelon
Link to comment
Share on other sites

The biggest thing you need is to realize that indexes are 0-based, so the loop would be:

For $i = 0 to $iterations - 1
     ; ...
Next

Then the loop uses $i as the iterated variable.

Also the Sleep(500) delay was too long to reliably catch the mouse click.

Here's a working demo of the basics:

#include <Misc.au3>
#include <Array.au3>

;Get Input from user, ie: How Many Iterations?
$iterations = InputBox("Input Needed", "How Many Iterations?", "Enter a number 1-100", "", -1, -1, 0, 0)

Global $aList[2][$iterations]

For $i = 0 To Int($iterations) - 1

    SplashTextOn("Setup", "Leftclick Where You Need To...", 400, 100, -1, -1, 1, "Ariel", 14)
    While 1
        If _IsPressed("01") Then
            $pos = MouseGetPos()
            ExitLoop
        EndIf
        Sleep(10)
    WEnd

    $aList[0][$i] = $pos[0]
    $aList[1][$i] = $pos[1] ;HOW DO I ADVANCE THESE VARIABLES FOR THE NEXT MOUSE CLICK?[/b]
    SplashTextOn("Setup", "Click no. " & $i & " saved.", 400, 100, -1, -1, 1, "Ariel", 14)
    Sleep(1000)
Next
SplashOff()

_ArrayDisplay($aList, "Debug: $aList")

And welcome to AutoIt.

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

thanks again for your insight, just for the record it works great, below is my working app!

Global $Paused 
HotKeySet("{PAUSE}", "TogglePause") 
HotKeySet("{INS}", "Terminate") 

#include <Misc.au3>
#include <Array.au3>

;Get Input from user, ie: How Many Iterations?
$iterations = InputBox("Input Needed", "How Many Iterations?", "Enter a number 1-100", "", -1, -1, 0, 0)

Global $aList[2][$iterations]

For $i = 0 To Int($iterations) - 1

    SplashTextOn("Setup", "Leftclick Where You Need To...", 400, 100, -1, -1, 1, "Ariel", 14)
    While 1
        If _IsPressed("01") Then
            $pos = MouseGetPos()
            ExitLoop
        EndIf
        Sleep(10)
    WEnd

    $aList[0][$i] = $pos[0]
    $aList[1][$i] = $pos[1] 
    SplashTextOn("Setup", "Click no. " & $i & " saved.", 400, 100, -1, -1, 1, "Ariel", 14)
    Sleep(1000)
Next
SplashOff()

Sleep(1000)
;_ArrayDisplay($aList, "Debug: $aList")

$delay = InputBox("Input Needed", "How Many Seconds Between clicks?", "Enter a number 1-10", "", -1, -1, 0, 0)

$delay = $delay * 1000  

$n = 0

While 1
    If $n = Int($iterations)Then $n=0
    Sleep($delay)
    MouseClick ("left", $aList[0][$n], $aList[1][$n], 1) 
    $n = $n+1
WEnd 


;KILL THIS PROGRAM
Func Terminate() 
   Exit 0 
EndFunc 

;Pause Script 
Func TogglePause() 
$Paused = NOT $Paused 
While $Paused 
sleep(100) 
ToolTip('Script Paused',0,0) 
WEnd 
ToolTip("") 
EndFunc
Link to comment
Share on other sites

  • 3 weeks later...

Well that worked great, I added a new feature to it, and it works... sort of..

The app asks for the number of clicks to be recorded, then records the clicks (left or right), then asks if variable delays will be used or not, if not a single # of secs is asked for and thats the number used between repeating the recorded clicks. If variable timers is selected, the app asks for the number of secs between each click one by one til completed.

The problem is, the array shows to have captured the clicks correctly, but when it repeats them, the order is off by 1...

Global $Paused 
HotKeySet("{PAUSE}", "TogglePause") 
HotKeySet("{INS}", "Terminate") 

#include <Misc.au3>
#include <Array.au3>

;Get Input from user, ie: How Many Iterations?
$iterations = InputBox("Input Needed", "How Many Iterations?", "Enter a number 1-100", "", -1, -1, 0, 0)

Global $aList[3][$iterations]
Global $timer[$iterations]

For $i = 0 To Int($iterations) - 1

    SplashTextOn("Setup", "Click Where You Need To...", 400, 100, -1, -1, 1, "Ariel", 14)
    While 1
        If _IsPressed("01") Then
            $pos = MouseGetPos()
                $aList[0][$i] = $pos[0]
                $aList[1][$i] = $pos[1]
                $aList[2][$i] = 1
            ExitLoop
        ElseIf _IsPressed("02") Then    
            $pos = MouseGetPos()
                $aList[0][$i] = $pos[0]
                $aList[1][$i] = $pos[1]
                $aList[2][$i] = 2
            ExitLoop
        EndIf
        Sleep(10)
    WEnd

 ; 1 = L  2 = R
 
    SplashTextOn("Setup", "Click no. " & $i +1 & " saved.", 400, 100, -1, -1, 1, "Ariel", 14)
    Sleep(1500)
Next
SplashOff()

Sleep(1000)


;variable timer
$n = 0
$question = InputBox("Input Needed", "Variable Timers? (Y/N)", "Enter Y or N", "", -1, -1, 0, 0)

If $question = "N" then 
    $delay = InputBox("Input Needed", "How Many Seconds Between clicks?", "Enter a number 1-10", "", -1, -1, 0, 0)
ElseIf $question = "Y" Then
    
    For $n = 0 To Int($iterations) - 1
        $timer[$n] = InputBox("Input Needed", "How Many Seconds after click?", "Number of seconds", "", -1, -1, 0, 0)
        
    Next

EndIf

;_ArrayDisplay($timer, "Debug: $aList")

;end variable timer


$x = 0

Sleep(5000)

While 1
            
    If $x = Int($iterations)Then $x=0
        If $question = "N" then 
            $delay = $delay * 1000
        ElseIf $question = "Y" Then
            $delay = $timer[$x] *1000
    EndIf
            Sleep($delay)
    Select
        
    case $aList[2][$x] = 1  
        MouseClick ("left", $aList[0][$x], $aList[1][$x], 1) 
    
    case $aList[2][$x] = 2  
        MouseClick ("right", $aList[0][$x], $aList[1][$x], 1)
        
    EndSelect
    $x = $x+1
    
WEnd 


;KILL THIS PROGRAM
Func Terminate() 
   Exit 0 
EndFunc 

;Pause Script 
Func TogglePause() 
$Paused = NOT $Paused 
While $Paused 
sleep(100) 
ToolTip('Script Paused',0,0) 
WEnd 
ToolTip("") 
EndFunc

Any suggestions.. The answer is right there on the edge of my mind, but I can't quite seem to get it..

Link to comment
Share on other sites

Well the part you're referring to works perfectly.

$x = 0

Sleep(5000)

While 1
            
    If $x = Int($iterations)Then $x=0
        If $question = "N" then 
            $delay = $delay * 1000
        ElseIf $question = "Y" Then
            $delay = $timer[$x] *1000
    EndIf
            Sleep($delay)
    Select
        
    case $aList[2][$x] = 1  
        MouseClick ("left", $aList[0][$x], $aList[1][$x], 1) 
    
    case $aList[2][$x] = 2  
        MouseClick ("right", $aList[0][$x], $aList[1][$x], 1)
        
    EndSelect
    $x = $x+1
    
WEnd

this is the part that's giving me headaches. when it calls the saved time delays the order is called wrong and for the life of me i can't figure out why.

Example, I record 3 clicks, use variable delays, and choose 2, 4, and 6 secs.

When playback begins, it starts with 4, then 6, then 2 then repeats...

Edited by exfelon
Link to comment
Share on other sites

Very confusing, or maybe I'm just sleepy.

In your place I'd record the data like this :

$aList[$i][0] = $pos[0]

$aList[$i][1] = $pos[1]

$aList[$i][2] = 1

instead of the other way around ...

thanks for posting that btw, don't think i do not appreciate comments/criticism...
Link to comment
Share on other sites

Well the part you're referring to works perfectly.

$x = 0

Sleep(5000)

While 1
            
    If $x = Int($iterations)Then $x=0
        If $question = "N" then 
            $delay = $delay * 1000
        ElseIf $question = "Y" Then
            $delay = $timer[$x] *1000
    EndIf
            Sleep($delay)
    Select
        
    case $aList[2][$x] = 1  
        MouseClick ("left", $aList[0][$x], $aList[1][$x], 1) 
    
    case $aList[2][$x] = 2  
        MouseClick ("right", $aList[0][$x], $aList[1][$x], 1)
        
    EndSelect
    $x = $x+1
    
WEnd

this is the part that's giving me headaches. when it calls the saved time delays the order is called wrong and for the life of me i can't figure out why.

Example, I record 3 clicks, use variable delays, and choose 2, 4, and 6 secs.

When playback begins, it starts with 4, then 6, then 2 then repeats...

That looks really confused. What does $aList contain before that loop starts? Why are you iterating the second index instead of the first? Is that data really stored in the array that way?

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

$aList contains the X & Y positions of the mouse click & whether it was a left or right mouse click.

I'm not sure why I did it that way tbh, there was a reason originally, but then the idea changed and I didn't redo that part... Ok so that's changed now...

Global $Paused 
HotKeySet("{PAUSE}", "TogglePause") 
HotKeySet("{INS}", "Terminate") 

#include <Misc.au3>
#include <Array.au3>

;Get Input from user, ie: How Many Iterations?
$iterations = InputBox("Input Needed", "How Many Iterations?", "Enter a number 1-100", "", -1, -1, 0, 0)

Global $aList[3][$iterations]
Global $timer[$iterations]

For $i = 0 To Int($iterations) - 1

    SplashTextOn("Setup", "Click Where You Need To...", 400, 100, -1, -1, 1, "Ariel", 14)
    While 1
        If _IsPressed("01") Then
            $pos = MouseGetPos()
                $aList[$i][0] = $pos[0]
                $aList[$i][1] = $pos[1]
                $aList[$i][2] = 1
            ExitLoop
        ElseIf _IsPressed("02") Then    
            $pos = MouseGetPos()
                $aList[$i][0] = $pos[0]
                $aList[$i][1] = $pos[1]
                $aList[$i][2] = 2
            ExitLoop
        EndIf
        Sleep(10)
    WEnd

 ; 1 = L  2 = R
 
    SplashTextOn("Setup", "Click no. " & $i +1 & " saved.", 400, 100, -1, -1, 1, "Ariel", 14)
    Sleep(1500)
Next
SplashOff()

Sleep(1000)
;_ArrayDisplay($aList, "Debug: $aList")


;variable timer

$question = InputBox("Input Needed", "Variable Timers? (Y/N)", "Enter Y or N", "", -1, -1, 0, 0)

If $question = "N" then 
    $delay = InputBox("Input Needed", "How Many Seconds Between clicks?", "Enter a number 1-10", "", -1, -1, 0, 0)
ElseIf $question = "Y" Then
    
    For $n = 0 To Int($iterations) - 1
        $timer[$n] = InputBox("Input Needed", "How Many Seconds after click?", "Number of seconds", "", -1, -1, 0, 0)
        
    Next

EndIf

_ArrayDisplay($aList, "Debug: $aList")
_ArrayDisplay($timer, "Debug: $timer")

;end variable timer


$x = 0

Sleep(5000)


While 1
    
    For $x = 0 To Int($iterations) - 1
            
            
        If $question = "N" then 
            $delay = $delay * 1000
        ElseIf $question = "Y" Then
            $delay = $timer[$x] *1000
    EndIf
            Sleep($delay)
    Select
        
    case $aList[$x][2] = 1  
        MouseClick ("left", $aList[$x][0], $aList[$x][1], 1) 
    
    case $aList[$x][2] = 2  
        MouseClick ("right", $aList[$x][0], $aList[$x][1], 1)
        
    EndSelect
    ;$x = $x+1
    
    
    Next
WEnd 


;KILL THIS PROGRAM
Func Terminate() 
   Exit 0 
EndFunc 

;Pause Script 
Func TogglePause() 
$Paused = NOT $Paused 
While $Paused 
sleep(100) 
ToolTip('Script Paused',0,0) 
WEnd 
ToolTip("") 
EndFunc

So... Problem is the timers are still off for some reason, like I had originally stated. If I store the values 2, 4, & 6 for the timers, it starts with the 4 value.... I just don't get why... I really want to LEARN why that part isn't working...

Edited by exfelon
Link to comment
Share on other sites

You didn't fix your backwards indexes:

; Global $aList[3][$iterations] ; <--- wrong
Global $aList[$iterations][3]

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

thanks, missed that psaltyds.. still does the same tho with the pauses being out of order, starts with the 2nd pause...

I think it only looks that way because you are doing the delay BEFORE the clicks, even though the prompt is "How Many Seconds after click?".

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...