Jump to content

Repeating script using a value in an array

Recommended Posts

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
    sleep $int


Link to post
Share on other sites

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

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


Link to post
Share on other sites

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
Link to post
Share on other sites

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.

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...