Autohotkey 自动热键在循环中迭代,但仅在键与输入匹配时返回值
假设我有以下几点Autohotkey 自动热键在循环中迭代,但仅在键与输入匹配时返回值,autohotkey,Autohotkey,假设我有以下几点 ^!r:: InputBox, input, Enter the string if (input = "trip") { TripFunction() } else if (input = "leave") { LeaveFunction() } else { Msgbox, That word isnt defined. } Return 但是,考虑到必须添加许多不同的测试用例,我认为最好的办法是将其放入一个
^!r::
InputBox, input, Enter the string
if (input = "trip")
{
TripFunction()
}
else if (input = "leave")
{
LeaveFunction()
}
else
{
Msgbox, That word isnt defined.
}
Return
但是,考虑到必须添加许多不同的测试用例,我认为最好的办法是将其放入一个数组中,并在数组中迭代,寻找匹配的键,返回值(函数),不再在字典中迭代。现在,我有了这样的东西:
^!r::
InputBox, input, Enter the string
dict = { "trip": TripFunction(), "leave": LeaveFunction() }
for k, v in dict
{
...
see if k = "trip", if so, return TripFunction(), if not, go to next
item in array
...
}
Return
我遇到的问题是,一旦它成功匹配字典中的akey,它将返回所有相关的值。我应该在括号中放些什么来做我想做的事?您使用的是错误的(对于非文字赋值,使用:=
,而不是=
)
另外,在第行dict={“trip”:TripFunction(),“leave”:LeaveFunction()}
中,执行您可能不希望执行的TripFunction ain和LeaveFunction
尝试:
您使用的是错误的(对于非文字赋值,请使用:=
,而不是=
)
另外,在第行dict={“trip”:TripFunction(),“leave”:LeaveFunction()}
中,执行您可能不希望执行的TripFunction ain和LeaveFunction
尝试:
这正是我想要的。您的示例清楚地说明了如何在autohotkey中使用和提及。非常感谢@马里奥不客气!XD你可能想考虑接受这个答案,否则别人会认为这个问题没有解决,这正是我想要的。您的示例清楚地说明了如何在autohotkey中使用和提及。非常感谢@马里奥不客气!XD你可能想考虑接受这个答案,否则别人会把这个问题看成是未解决的。
^!r::
InputBox, input, Enter the string
dict := { "trip": "TripFunction", "leave": "LeaveFunction" }
for k, v in dict
{
if(k==input) {
%v%() ; documentation: https://autohotkey.com/docs/Functions.htm#DynCall
break
}
}
Return
TripFunction() {
msgbox trip
}
LeaveFunction() {
msgbox leave
}