我想创建一个脚本,让我通过按热键一个接一个地从数组中发送字符串。 (按一次,然后发送第一行,再次按下,第二行发送,依此类推)但是我(迄今为止有限)对AutoHotKey的理解使我失望。
这就是我到目前为止(“借用”从ahk网站构建数组的那一点)
;Write to the array:
ArrayCount = 0
Loop, Read, C:\My_little_dir\test.txt{ ;test.txt contains 6-digit numbers separated only by ENTER/newline.
ArrayCount += 1 ; Keep track of how many items are in the array.
Arr_Bookings%ArrayCount% := A_LoopReadLine ; Store this line in the next array element.
}
element=1
Change(direction, element, ArrayCount){
if (direction = "next"){
;incrementing from the last element gets us back to the first element
if (element = %ArrayCount%)
{element=1}
else
{element+=1}
}
else{
if (direction = "previous"){
;decrementing from the first element gets us back to the last element
if (element=0)
{element=%ArrayCount%}
else
{element-=1}
}
}
Return Arr_Bookings%element%
}
#N::Send % Change(next,element, ArrayCount)
#B::Send % Change(previous,element, ArrayCount)
然而,当我运行它时,我收到错误消息:
行文本:#N ::发送更改(next,element,ArrayCount)
错误:函数内部不允许使用热键/热字符串。
我已经反复检查过乱搞花括号,但无济于事(空白无关紧要......对吧?)。
任何想法导致了什么?
此外,如果您发现此代码还有其他可怕错误,请随时提及。
提前致谢! /利奥
答案 0 :(得分:0)
Autohotkey不喜欢你的缩进风格。使用Allman style。
即。将每个支架放在自己的线上,如果不需要,不要使用它;例如:
if (element = %ArrayCount%)
{element=1}
else
{element+=1}
这里的括号完全是多余的。
我通常不会这样做但是因为我已经有了代码,所以这是展开的代码:
;Write to the array:
ArrayCount = 0
Loop, Read, C:\My_little_dir\test.txt
{ ;test.txt contains 6-digit numbers separated only by ENTER/newline.
ArrayCount += 1 ; Keep track of how many items are in the array.
Arr_Bookings%ArrayCount% := A_LoopReadLine ; Store this line in the next array element.
}
element=1
Change(direction, element, ArrayCount)
{
if (direction = "next")
{
;incrementing from the last element gets us back to the first element
if (element = %ArrayCount%)
{
element=1
}
else
{
element+=1
}
}
else
{
if (direction = "previous")
{
;decrementing from the first element gets us back to the last element
if (element=0)
{
element=%ArrayCount%
}
else
{
element-=1
}
}
}
Return Arr_Bookings%element%
}
#N::Send Change(next,element, ArrayCount)
#B::Send Change(previous,element, ArrayCount)