Autohotkey - 字母循环

时间:2014-09-23 12:16:25

标签: autohotkey modulo

我是一名数学学生,我知道模运算可能会有所帮助。

我希望在按键点击时使用Autohotkey或自动进行编码我想要运行一系列输入命令,例如:

A A A A A A A A 输入

A A A A A A A 输入

...

A A A A A A A 输入

我想循环通过这些字母到

ž ž ž ž ž ž ž ž 输入

  

我希望生成以 Enter

分隔的字母a-z的所有12个长度排列

我会按照我的要求开展工作,非常感谢任何提示。

1 个答案:

答案 0 :(得分:4)

2个星期前提出了几乎相同的问题:Counting with AHK, Letters 但我很乐意再次回答:
(单击上面的链接以获得无评论的示例,此处非常混乱)

BruteForce(Chars, Min, Max, Prefix:="", Stage:=0) { ;function header
   Loop, Parse, Chars ;We loop through the character string that we are gonna pass to this function
   {
      If (Stage >= Min-1) { ;explained in the second if block
           ;Prefix: our last generated string (at the first iteration AAAAAAAAAAA (11 As))
           ;A_LoopField: contains current character of the "Chars" string that we are looping through
           ;"{Enter}": to tell SendInput to send an Enter after the Prefix and the current char
         SendInput % Prefix A_loopField "{Enter}" ;AAAAAAAAAAA A {Enter}
      }
      If (Stage < Max-1) { 
           ;at this point it get really tricky
           ;it's kinda hard to explain what exactly happens here
           ;and at the same time pretty selfexplainatory if you simply know the used AHK commands/keywords

           ;Basically what happens here is, the function is going to call itself again without leaving the loop
           ;increasing the state step by step (everytime we get here) until we reach (in this case) 12-1 so 11
           ;during the first "iteration" (in this case) we will be adding an A to the prefix parameter everytime the function re-calls itself
           ;when it reached 11, then it generated the string AAAAAAAAAAA (11 As)
           ;since the is at this point the expression state >= Min-1 (we passed a 12 for Min) is true
           ;we will output the the string + the current char (A) in the if block above
           ;then the second if statement will fail 
           ;and the loop of the current function call will go into it's second iteration
           ;and output again 11 As and our second character (B)
           ;etc etc until the loop is over, then the last function call is over and it will go to the one from before... 
           ;as I said... really hard to explain. to understnad it you are best of with simply going through the code like it would be executed and maybe take some notes of what has happened in each iteration
         BruteForce(Chars, Min, Max, Prefix A_LoopField, Stage + 1)
      }
   }
}

F1:: ;hotkey is F1
    BruteForce("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 12, 12) ;this would send possible combination of capital letters (min length 12, max length 12)
    ;you can change the min length and max length, as well as the character string however you want
Return

如果最小和最大长度不同,这里有一种不同的方法可以提供更多排序的输出:

Generate(prefix, len, chars) {
    If (StrLen(prefix) = len)
        SendInput % prefix " "
    If (StrLen(prefix) < len)
        Loop, Parse, chars
            Generate(prefix A_LoopField, len, chars) 
}

BruteForce(chars, minLen, maxLen) {
    curLen := minLen
    Loop % maxLen-minLen+1 {
        Generate("", curLen, chars)
        curLen++
    }
}

F1::
   BruteForce("abc", 2, 3)
Return

输出为:aa ab ac ba bb bc ca cb cc aaa aab aac aba abb abc aca acb acc baa bab bac bba bbb bbc bca bcb bcc caa cab cac cba cbb cbc cca ccb ccc