Autohotkey-尝试发送数组的特定位置

时间:2019-02-11 18:47:52

标签: autohotkey

我正在尝试发送数组的特定部分

我的代码尝试输入字符串指定次数。

如果有人知道一种更好的方法,我很乐意

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

i = 0 ; Used for a loop


InputBox, x, String, Please enter your string
InputBox, y, No. of times, Please enter the no. of times you want to run the string
k = `n ;used to concatenate strings
z = %x%%k% ;concatenating the input with new lines

F10:: 
while (i < y) { ;While the loop has run less than the required number of times
    i++ ;increment the number of times the loop has run
    l = 0 ;used to run a loop a certain number of times
    a = StrSplit(%s%) ;Splits the string created earlier
    send %a% ;For debug
    g = 0 ;used as a value for cycling through arrays
    while (l < StrLen(s)) { 
        h = a[g] ;creates a variable for a specified position in the string
        g++
        Random, rand, 10, 100 ;creates a variable to wait a random amount of time
        r = %rand% ;assigns a random value to a variable for debug
        FileAppend, Loop - %h% `n, C:\Users\charl\Desktop\Code\AutoHotkey\Debug.txt ;all file usage is for debug
        FileAppend Rand - %r% `n `n, C:\Users\charl\Desktop\Code\AutoHotkey\Debug.txt
        send %h% ;sends a character of the original string
        Sleep %r% ;sleeps a random amount of time

}
}

对不起,代码太乱了,很难理解

1 个答案:

答案 0 :(得分:0)

适用于此特定功能的代码是:

InputBox, str, String, Please enter your string
InputBox, amt, No. of times, Please enter the no. of times you want to run the string

Return

F10::
Loop, %amt% { 
    For k,v in StrSplit(str) {
        ToolTip, now %A_Index%
        Random, rand, 10, 100 ;creates a variable to wait a random amount of time
        ;FileAppend %v%`n`n, %A_WorkingDir%\Debug.txt
        Send, % v "`n"
        Sleep, % rand ;sleeps a random amount of time

    }
}