【问题标题】:How to use Autohotkey Send Command with Arrays?如何使用带有数组的 Autohotkey 发送命令?
【发布时间】:2019-05-09 00:59:58
【问题描述】:

我想将击键发送到 HTerm 并通过记事本对其进行协议 对所有发送进行硬编码工作正常,但一旦我尝试使用数组和循环就没有任何效果(甚至没有激活窗口)

我已经使用 Light%A_index%、%Light%A_index%、%LightA_index%、Light[A_index] 等的所有组合尝试了以下代码。

Initialization_Loading_1:

Light := ["F0281", "F0282", "F0283", "F0284", "F0285", "F0286", "F0287", "F0288"] ; Define Array

Return

^2::
Loop % Light.Lenght() ; Send Array to HTerm and Protocol with notepad via Loop
{
IfWinExist, HTerm 0.8.1beta
WinActivate ;
Sender := Light%A_index%
Send, %Sender%
Send, {Enter}
Sleep, 100
IfWinExist, Protokoll.txt - Notepad
WinActivate ;
Send, %Sender%
Send, {Enter}
Sleep, 5000
}
Return

预期的结果应该是在 Hterm 中输入命令,然后在记事本中输入命令,而不是像它甚至没有启动循环一样没有任何反应。

【问题讨论】:

    标签: autohotkey


    【解决方案1】:

    我使用了您的部分代码进行测试(显示在底部)。

    将数组元素(“Light”)保存到变量(“Sender”)的正确方法是 Sender := Light[A_Index]

    您的循环中还有一个错字;它应该是Loop , % Light.Length()(添加的逗号是可选的,但我喜欢它的一致性)。我相信错字可能是您没有看到任何事情发生的原因。

    (这不是问题,但可能会使您的代码更简洁。)还有其他使用数据的方法。一种选择是直接发送数组元素,例如Send , % Light[A_Index]。另一种选择可能是使用 for 循环。这是基于您的代码的示例:

    ^3::
    Light := ["F0281", "F0282", "F0283", "F0284", "F0285", "F0286", "F0287", "F0288"] ; Define Array
    For x In Light
    {
        Send , % Light[x] . "{enter}"
        Sleep , 100
    }
    Return
    

    用于测试的代码(工作):

    ^2::
    Light := ["F0281", "F0282", "F0283", "F0284", "F0285", "F0286", "F0287", "F0288"] ; Define Array
    Loop , % Light.Length() ; Send Array to HTerm and Protocol with notepad via Loop
    {
        Sender := Light[A_Index]
        Send , %Sender%
        Send , {Enter}
        Sleep , 100
    }
    Return
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-28
      相关资源
      最近更新 更多