Jump to content
Sign in to follow this  
shocki3

Repeating script using a value in an array

Recommended Posts

shocki3

So I have no knowledge of how to script in autoIT. Was wondering if anyone could point me in the right direction of creating a script based on the following. It needs to increment by 1 each time the key value iterates. The key presses should occur after the designated reference time(int), determined by the value of key presses(i) that have occurred.


int=0.60 ;time between initial key presses
for i in {1..100000} do
    keydown x
    sleep 0.05
    keyup x


    if i==20 then
        int=0.455 ; time of iteration after 20 key presses
    ElseIf i==50 then
        int=0.392 ; time of iteration after 50 key presses
    ElseIf i==100 then
        int=0.350 ; time of iteration after 100 key presses
    ElseIf i==200 then
        int=0.3065 ; time of iteration after 200 key presses
    ElseIf i==300 then
        int=0.320 ; time of iteration after 300 key presses
    Else
    sleep $int
done

 

Share this post


Link to post
Share on other sites
shocki3

Hi InunoTaishou,

Thanks for the links! I made some adjustments to reflect the correct syntax, but am unsure of how they all fit together.

Dim $int = 0.60 ;time between inital key presses
Dim $i = 1

   While $i <= 1001 
    Send("{x down}")
    Sleep 0.05
    Send("{x up}")
    $i += 1
   WEnd

Func jump()
    If $i = 20 then
        $int = 0.455 ; time of key press after 20 key presses
    ElseIf $i = 50 then
        $int = 0.392 ; time of key press after 50 key presses
    ElseIf $i = 100 then
        $int = 0.350 ; time of key press after 100 key presses
    ElseIf $i = 200 then
        $int = 0.3065 ; time of key press after 200 key presses
    ElseIf $i = 300 then
        $int = 0.320 ; time of key press after 300 key presses
    ElseIf $i = 10001
    EndIf

 EndFunc

Share this post


Link to post
Share on other sites
markyrocks

Couple of thoughts.   1.  Dim is bad,  use local or global instead.  

2. Any function such as sleep always has parentheses at the end of the name. "Sleep ($arg)" 

3.  You have no function call.  Jump () will never run in your script.

4.  It looks like your using math to determine time ?  Use TimerInit () and TimerDiff () instead

5.  Sleep (1)=1ms so a fraction of this is essentially nothing.   1ms is basically nothing.

O and I like how you used $int for a floating point number.  Not really a big deal but not the best of habits.

Edited by markyrocks

Share this post


Link to post
Share on other sites
shocki3

Hi Marky, 

I am trying to count the number of times x is pressed and increment it by one. While applying a delay based off int variable. When the number of key presses of x reaches a certain number, the time between key presses changes based off int.

Share this post


Link to post
Share on other sites
InunoTaishou
Local $int = 600    ; Time between initial key pressed
For $i = 1 to 100000
    Send("{x Down}")
    Sleep(500)
    Send("{x Up}")
    
    If ($i = ...) Then
    
    ElseIf ($i = ...) Then
    ...
    EndIf
    
    Sleep($int)
Next

 

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  

×