开发者

AutoHotKey: Hot key randomly chooses one of several pre-chosen strings

What is th开发者_C百科e simplest way to create a list of possible strings and then have a hot key randomly type out one of them?

By way of explanation, in python it would be...

random.choice(["Hi, dork.", "Hello, titmouse.", "Greetings, ass.", "Sup, barnacle."])


One way:

F2::
Values = pick,one of,these,choices
StringSplit, ValueArray, Values, `,
Random, rand, 1, 4
SendInput % ValueArray%rand%

I haven't found a good way to get the array size.


if you need to handle commas inside of each list item, you can just use a separate delimiter.

F2::
   list := "Hi, dork.;Hello, titmouse.;Greetings, ass.;Sup, barnacle."
   listsize := list#items(list, ";")
   Random, rand, 1, %listsize%
   MsgBox, % listGet(list, rand, ";")
return


; return item at said position in said list
listGet(list,pos=1,del=",") {
   StringSplit, item, list, %del%
   return item%pos%
}


; returns # of items 
list#items(list, del=",") {
   ifEqual, list,, return 0
   StringReplace, var, list, % del,, useErrorLevel
   return ErrorLevel+1
}

more list manipulation functions here: http://www.autohotkey.com/forum/topic3195.html


Try this

Voice := ComObjCreate("SAPI.SpVoice")

F2::        ;Press F2
Random, rand, 1, 4
goto, %rand%

1:
Voice.Speak("number 1")
; Or you can use    send 1
return

2:
Voice.Speak("number 2?")
return

3:
Voice.Speak("number 3")
return

4:
Voice.Speak("number 4")
return
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜