Autohotkey 函数内部不允许使用AHK热键
我想创建一个脚本,让我从一个数组发送字符串,一个接一个地按下热键。按一次,发送第一行,再按一次,发送第二行,依此类推,但我对自动热键的有限理解使我无法理解 这是我迄今为止从ahk站点“借用”的关于构建阵列的部分Autohotkey 函数内部不允许使用AHK热键,autohotkey,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.
;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::发送更改下一步,元素,数组计数
错误:函数内不允许热键/热字符串
我一次又一次地检查有没有弄乱的花括号,但没有结果,空白没有任何意义……对吧
你知道这是什么原因吗
此外,如果您看到这段代码还有其他可怕的错误,请随时提及
提前谢谢!
/Leo自动热键不喜欢缩进样式。使用 i、 e.将每个括号放在自己的行中,如果不需要,不要使用它;例如:
if (element = %ArrayCount%)
{element=1}
else
{element+=1}
这里的大括号是完全多余的
我通常不会这样做,但因为我已经有了代码,下面是您展开的代码:
来自Python,我对这些不同的括号样式经验有限。谢谢你的指点!
;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)