AHK 在不使用#Include Subroutines.ahk 的情况下加载热字串

AHK Load hotstrings without using #Include Subroutines.ahk

我有一个名为 subroutines.ahk 的 txt 文件,里面是下面的热字串。

::btw::Thank you for the help

我知道如果我想 运行 我的热字串来自另一个脚本我所要做的就是将它包含在该脚本中使用:

#include subroutines.ahk

但我不想那样做 我想从另一个脚本循环读取 subroutines.ahk 的内容并以这种方式加载热字符串变量。

Loop, read,subroutines.ahk
{
  Loop, parse, A_LoopReadLine, %A_Tab%
{
    MsgBox, Field number %A_Index% is %A_LoopField%.
}
}

非常感谢您帮助我如何以这种方式将我的热字串变量加载到另一个脚本中。

我计划在 subroutines.ahk 中对热环进行编码,然后在第二个程序中解码 subroutines.ahk 的内容并将其加载到内存中。 在上面的示例中,虽然我首先试图弄清楚如何循环读取 txt 文件并从那里 运行 热字符串。

# 指令仅在启动脚本时处理一次。要解决此限制,您可以使用 reload 来执行包含 # 指令的动态生成的脚本。

代码示例:

按下 F1 时,使用 "subroutines.ahk" 的内容生成 运行 使用 # 指令的代码:

F1:: reload_hotstrings()

#Include temp.ahk

reload_hotstrings()
{
  FileDelete temp.ahk
  loop read, subroutines.ahk
  {
    MsgBox Hotstring number %A_Index% is %A_LoopReadLine%.
    FileAppend %A_LoopReadLine%`n, temp.ahk
  }
  reload
}

或者,如果您想在自动热键启动时自动生成热键代码:

我正在为你的 subroutines.ahk 文件使用 source.dat

代码示例:

FileGetTime source_time,   source.dat
FileGetTime compiled_time, compiled.ahk
; calculate time difference between source and compiled files
EnvSub source_time, %compiled_time%, Seconds

; compile and run if source newer
if source_time > 0
{
  FileDelete compiled.ahk
  loop read, source.dat
  {
    FileAppend %A_LoopReadLine%`n, compiled.ahk
  }
  reload
}

#Include compiled.ahk

演示映射到动态值的热键的使用

; Replace hash values with whatever method you use to decrypt your hotstrings
decrypted := {abc: "alpha", def: "beta"}

::abc::
  Send % decrypted["abc"]
  return
::def::
  Send % decrypted["def"]
  return

当您键入 "abc" 时,"alpha" 会出现